vilarin commited on
Commit
5ae861e
·
verified ·
1 Parent(s): 84a19ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -32,7 +32,7 @@ def process_text(text_input, unit):
32
  return completion.choices[0].message.content
33
  return ""
34
 
35
- def encode_image_to_base64(image):
36
  buffered = io.BytesIO()
37
  image.save(buffered, format="JPEG")
38
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
@@ -42,7 +42,7 @@ def process_image(image_input, unit):
42
  if image_input is not None:
43
  #with open(image_input.name, "rb") as f:
44
  # base64_image = base64.b64encode(f.read()).decode("utf-8")
45
- base64_image = encode_image_to_base64(image)
46
  response = client.chat.completions.create(
47
  model=MODEL,
48
  messages=[
@@ -80,13 +80,13 @@ with gr.Blocks() as iface:
80
  with gr.Row():
81
  output_box = gr.Markdown(label="分析") # Create an output textbox
82
  with gr.Row():
83
- image_btn = gr.Image(type="filepath", label="上传图片") # Create an image upload button
84
  text_input = gr.Textbox(label="输入") # Create a text input box
85
  with gr.Row():
86
  submit_btn = gr.Button("🚀 确认") # Create a submit button
87
  clear_btn = gr.ClearButton(output_box, value="🗑️ 清空") # Create a clear button
88
 
89
  # Set up the event listeners
90
- submit_btn.click(main, inputs=[text_input, image_btn, unit], outputs=output_box)
91
 
92
  iface.launch() # Launch the Gradio interface
 
32
  return completion.choices[0].message.content
33
  return ""
34
 
35
+ def encode_image_to_base64(image_input):
36
  buffered = io.BytesIO()
37
  image.save(buffered, format="JPEG")
38
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
 
42
  if image_input is not None:
43
  #with open(image_input.name, "rb") as f:
44
  # base64_image = base64.b64encode(f.read()).decode("utf-8")
45
+ base64_image = encode_image_to_base64(image_input)
46
  response = client.chat.completions.create(
47
  model=MODEL,
48
  messages=[
 
80
  with gr.Row():
81
  output_box = gr.Markdown(label="分析") # Create an output textbox
82
  with gr.Row():
83
+ image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
84
  text_input = gr.Textbox(label="输入") # Create a text input box
85
  with gr.Row():
86
  submit_btn = gr.Button("🚀 确认") # Create a submit button
87
  clear_btn = gr.ClearButton(output_box, value="🗑️ 清空") # Create a clear button
88
 
89
  # Set up the event listeners
90
+ submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
91
 
92
  iface.launch() # Launch the Gradio interface