Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,19 @@ def clean_response(response: str) -> str:
|
|
34 |
return response
|
35 |
|
36 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
query_elements = [
|
45 |
-
{'image':
|
46 |
{'text': text_input}
|
47 |
]
|
48 |
try:
|
@@ -52,9 +56,10 @@ def chat_with_model(image_path=None, text_query=None, history=None):
|
|
52 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
53 |
cleaned_response = clean_response(response)
|
54 |
return cleaned_response
|
55 |
-
except
|
56 |
-
|
57 |
-
|
|
|
58 |
def draw_boxes(image_path, response):
|
59 |
image = Image.open(image_path)
|
60 |
draw = ImageDraw.Draw(image)
|
|
|
34 |
return response
|
35 |
|
36 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
37 |
+
default_image_path = 'path/to/default/image.jpg'
|
38 |
+
if image_path and os.path.isfile(image_path):
|
39 |
+
try:
|
40 |
+
with Image.open(image_path) as img:
|
41 |
+
print(f"Image {image_path} opened successfully.")
|
42 |
+
except UnidentifiedImageError:
|
43 |
+
print(f"Error: The file at {image_path} is not a recognizable image.")
|
44 |
+
image_path = default_image_path
|
45 |
+
else:
|
46 |
+
image_path = default_image_path
|
47 |
+
text_input = text_query if text_query else ""
|
48 |
query_elements = [
|
49 |
+
{'image': image_path},
|
50 |
{'text': text_input}
|
51 |
]
|
52 |
try:
|
|
|
56 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
57 |
cleaned_response = clean_response(response)
|
58 |
return cleaned_response
|
59 |
+
except Exception as e:
|
60 |
+
print(f"An error occurred: {e}")
|
61 |
+
return "An error occurred while processing your request."
|
62 |
+
|
63 |
def draw_boxes(image_path, response):
|
64 |
image = Image.open(image_path)
|
65 |
draw = ImageDraw.Draw(image)
|