Tonic commited on
Commit
cbc52e9
·
1 Parent(s): 89be989

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -94,6 +94,16 @@ def draw_boxes(image_path, response):
94
  image.save(temp_file, format="PNG")
95
  return temp_file.name
96
 
 
 
 
 
 
 
 
 
 
 
97
  def process_input(text=None, file=None, task_history=None):
98
  if task_history is None:
99
  task_history = []
@@ -107,9 +117,12 @@ def process_input(text=None, file=None, task_history=None):
107
  task_history.append((text, response))
108
 
109
  if "<box>" in response and image_path:
110
- image_with_boxes_path = draw_boxes(image_path, response)
111
- cleaned_response = clean_response(response)
112
- return [("Qwen-VL_Image", (image_with_boxes_path, "Image with boxes")), ("Qwen-VL_Chat", cleaned_response)], task_history
 
 
 
113
  else:
114
  cleaned_response = clean_response(response)
115
  return [("Qwen-VL_Chat", cleaned_response)], task_history
 
94
  image.save(temp_file, format="PNG")
95
  return temp_file.name
96
 
97
+ def draw_boxes_with_tokenizer(response, history):
98
+ image = tokenizer.draw_bbox_on_latest_picture(response, history)
99
+ if image is not None:
100
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.png', dir=os.path.abspath("uploaded_images")) as temp_file:
101
+ image.save(temp_file, format="PNG")
102
+ return temp_file.name
103
+ else:
104
+ print("No box found or drawing failed.")
105
+ return None
106
+
107
  def process_input(text=None, file=None, task_history=None):
108
  if task_history is None:
109
  task_history = []
 
117
  task_history.append((text, response))
118
 
119
  if "<box>" in response and image_path:
120
+ image_with_boxes_path = draw_boxes_with_tokenizer(response, task_history)
121
+ if image_with_boxes_path:
122
+ cleaned_response = clean_response(response)
123
+ return [("Qwen-VL_Image", (image_with_boxes_path, "Image with boxes")), ("Qwen-VL_Chat", cleaned_response)], task_history
124
+ else:
125
+ return [("bot", "Unable to draw boxes on the image.")], task_history
126
  else:
127
  cleaned_response = clean_response(response)
128
  return [("Qwen-VL_Chat", cleaned_response)], task_history