dlimeng commited on
Commit
8d71bb6
·
1 Parent(s): 7b97ddf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -9,11 +9,11 @@ import re
9
 
10
  # 将图像转换为 base64,以便在 gradio 中显示
11
  def get_image_data(fig):
12
- buf = io.BytesIO()
13
- fig.savefig(buf, format='PNG')
14
- buf.seek(0)
15
- img = Image.open(buf)
16
- return img
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.outputs.Image(type="pil"),
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()