Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -33,19 +33,22 @@ def clean_response(response: str) -> str:
|
|
33 |
return response
|
34 |
|
35 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
if text_query
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
query = tokenizer.from_list_format(query_elements)
|
44 |
tokenized_inputs = tokenizer(query, return_tensors='pt').to(device)
|
45 |
output = model.generate(**tokenized_inputs)
|
46 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
47 |
cleaned_response = clean_response(response)
|
48 |
return cleaned_response
|
|
|
49 |
def draw_boxes(image_path, response):
|
50 |
image = Image.open(image_path)
|
51 |
draw = ImageDraw.Draw(image)
|
|
|
33 |
return response
|
34 |
|
35 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
36 |
+
|
37 |
+
default_image_path = 'path/to/default/image.jpg'
|
38 |
+
default_text = 'No text provided'
|
39 |
+
image_input = image_path if image_path else default_image_path
|
40 |
+
text_input = text_query if text_query else default_text
|
41 |
+
query_elements = [
|
42 |
+
{'image': image_input},
|
43 |
+
{'text': text_input}
|
44 |
+
]
|
45 |
query = tokenizer.from_list_format(query_elements)
|
46 |
tokenized_inputs = tokenizer(query, return_tensors='pt').to(device)
|
47 |
output = model.generate(**tokenized_inputs)
|
48 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
49 |
cleaned_response = clean_response(response)
|
50 |
return cleaned_response
|
51 |
+
|
52 |
def draw_boxes(image_path, response):
|
53 |
image = Image.open(image_path)
|
54 |
draw = ImageDraw.Draw(image)
|