Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,11 @@ import re
|
|
9 |
|
10 |
# 将图像转换为 base64,以便在 gradio 中显示
|
11 |
def get_image_data(fig):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
return
|
17 |
|
18 |
# 执行 Python 代码并生成图像
|
19 |
def execute_code(code):
|
@@ -71,7 +71,7 @@ def gpt_inference(base_url, model, openai_key, prompt):
|
|
71 |
iface = gr.Interface(
|
72 |
fn=gpt_inference,
|
73 |
inputs=["text", gr.inputs.Dropdown(choices=["gpt3.5-turbo", "gpt4"], label="Model"), "text", "text"],
|
74 |
-
outputs=gr.
|
75 |
input_labels=["Base URL", "Model", "OpenAI Key","Prompt"]
|
76 |
)
|
77 |
iface.launch()
|
|
|
9 |
|
10 |
# 将图像转换为 base64,以便在 gradio 中显示
|
11 |
def get_image_data(fig):
|
12 |
+
img_byte_arr = io.BytesIO()
|
13 |
+
img.save(img_byte_arr, format='PNG')
|
14 |
+
img_byte_arr = img_byte_arr.getvalue()
|
15 |
+
img_str = base64.b64encode(img_byte_arr).decode('utf-8')
|
16 |
+
return img_str
|
17 |
|
18 |
# 执行 Python 代码并生成图像
|
19 |
def execute_code(code):
|
|
|
71 |
iface = gr.Interface(
|
72 |
fn=gpt_inference,
|
73 |
inputs=["text", gr.inputs.Dropdown(choices=["gpt3.5-turbo", "gpt4"], label="Model"), "text", "text"],
|
74 |
+
outputs=gr.Image(),
|
75 |
input_labels=["Base URL", "Model", "OpenAI Key","Prompt"]
|
76 |
)
|
77 |
iface.launch()
|