artificialguybr commited on
Commit
7fc0578
1 Parent(s): ccd71e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import base64
5
  from PIL import Image
6
  import io
 
7
 
8
  def resize_image(image_path, max_size=(800, 800), quality=85):
9
  with Image.open(image_path) as img:
@@ -60,11 +61,15 @@ def call_fuyu_8b_api(image_path, content, temperature=0.2, top_p=0.7, max_tokens
60
  for line in response.iter_lines():
61
  if line:
62
  decoded_line = line.decode("utf-8")
63
- if "content" in decoded_line:
64
- response_text += decoded_line.split('"content":"')[1].split('","finish_reason')[0]
 
 
 
 
 
65
 
66
  return response_text
67
-
68
  content_input = gr.Textbox(lines=2, placeholder="Enter your content here...", label="Content")
69
  image_input = gr.Image(type="filepath", label="Upload Image")
70
  temperature_input = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.2, label="Temperature")
 
4
  import base64
5
  from PIL import Image
6
  import io
7
+ import json
8
 
9
  def resize_image(image_path, max_size=(800, 800), quality=85):
10
  with Image.open(image_path) as img:
 
61
  for line in response.iter_lines():
62
  if line:
63
  decoded_line = line.decode("utf-8")
64
+ try:
65
+ # Parse each line as JSON and extract the "content" part
66
+ json_line = json.loads(decoded_line)
67
+ content_part = json_line.get("delta", {}).get("content", "")
68
+ response_text += content_part
69
+ except json.JSONDecodeError:
70
+ print("Error decoding JSON from response line.")
71
 
72
  return response_text
 
73
  content_input = gr.Textbox(lines=2, placeholder="Enter your content here...", label="Content")
74
  image_input = gr.Image(type="filepath", label="Upload Image")
75
  temperature_input = gr.Slider(minimum=0, maximum=1, step=0.01, value=0.2, label="Temperature")