-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalAI.py
73 lines (55 loc) · 1.5 KB
/
LocalAI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import shutil
from io import BytesIO
from typing import Dict
import pandas as pd
# Import the EvaDB package
import evadb
# Connect to EvaDB and get a database cursor for running queries
import requests
from PIL import Image
from io import BytesIO
cursor = evadb.connect().cursor()
print(cursor.query("SHOW FUNCTIONS;").df())
def display_image_from_url(url):
response = requests.get(url)
if response.status_code == 200: # HTTP状态码200表示请求成功
image_data = BytesIO(response.content)
image = Image.open(image_data)
image.show()
else:
print(f"Failed to retrieve the image. HTTP Status Code: {response.status_code}")
query = cursor.query("""
CREATE FUNCTION
IF NOT EXISTS GenerateImage
IMPL 'test.py';
""")
# cursor.execute(query)
response = query.df()
input = "okok"
cursor.query("DROP TABLE IF EXISTS History").df()
cursor.query("""
CREATE TABLE History
(id INTEGER,
command TEXT(30),
data TEXT(30));
""").df()
cursor.query(f"""
INSERT INTO History (id, command, data ) VALUES
(1,
'{input}',
"null");
""").df()
query = cursor.query("""
SELECT * FROM History;
""").df()
# print(query)
query = cursor.query("""
SELECT GenerateImage(command).result FROM History;
""").df()
print(query)
# List all the built-in functions in EvaDB
print(cursor.query("SHOW FUNCTIONS;").df())
url_image = query['generateimage.result'].iloc[0]
display_image_from_url(url_image)
cursor.query("DROP FUNCTION GenerateImage").df()