Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ import torch
|
|
| 9 |
import os
|
| 10 |
import io
|
| 11 |
from io import BytesIO
|
|
|
|
|
|
|
| 12 |
from PIL import Image, ImageDraw, UnidentifiedImageError
|
| 13 |
|
| 14 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
|
@@ -97,9 +99,10 @@ def draw_boxes(image_path, response):
|
|
| 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 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
| 103 |
else:
|
| 104 |
print("No box found or drawing failed.")
|
| 105 |
return None
|
|
@@ -117,10 +120,10 @@ def process_input(text=None, file=None, task_history=None):
|
|
| 117 |
task_history.append((text, response))
|
| 118 |
|
| 119 |
if "<box>" in response and image_path:
|
| 120 |
-
|
| 121 |
-
if
|
| 122 |
cleaned_response = clean_response(response)
|
| 123 |
-
return [("Qwen-VL_Image",
|
| 124 |
else:
|
| 125 |
return [("bot", "Unable to draw boxes on the image.")], task_history
|
| 126 |
else:
|
|
|
|
| 9 |
import os
|
| 10 |
import io
|
| 11 |
from io import BytesIO
|
| 12 |
+
import base64
|
| 13 |
+
import PIL
|
| 14 |
from PIL import Image, ImageDraw, UnidentifiedImageError
|
| 15 |
|
| 16 |
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
|
|
|
| 99 |
def draw_boxes_with_tokenizer(response, history):
|
| 100 |
image = tokenizer.draw_bbox_on_latest_picture(response, history)
|
| 101 |
if image is not None:
|
| 102 |
+
buffered = io.BytesIO()
|
| 103 |
+
image.save(buffered, format="PNG")
|
| 104 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 105 |
+
return "data:image/png;base64," + img_str
|
| 106 |
else:
|
| 107 |
print("No box found or drawing failed.")
|
| 108 |
return None
|
|
|
|
| 120 |
task_history.append((text, response))
|
| 121 |
|
| 122 |
if "<box>" in response and image_path:
|
| 123 |
+
image_with_boxes_base64 = draw_boxes_with_tokenizer(response, task_history)
|
| 124 |
+
if image_with_boxes_base64:
|
| 125 |
cleaned_response = clean_response(response)
|
| 126 |
+
return [("Qwen-VL_Image", image_with_boxes_base64), ("Qwen-VL_Chat", cleaned_response)], task_history
|
| 127 |
else:
|
| 128 |
return [("bot", "Unable to draw boxes on the image.")], task_history
|
| 129 |
else:
|