Update app.py
Browse files
app.py
CHANGED
@@ -108,31 +108,27 @@ def _launch_demo(args, model, tokenizer):
|
|
108 |
if not _chatbot:
|
109 |
return _chatbot
|
110 |
chat_query = _chatbot[-1][0]
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
if isinstance(chat_query, tuple): # Image input
|
116 |
-
message = {'image': chat_query[0]}
|
117 |
-
else: # Text input
|
118 |
-
message = {'text': chat_query}
|
119 |
-
|
120 |
-
response, updated_history = model.chat(tokenizer, query=message, history=history)
|
121 |
-
|
122 |
-
if "<box>" in response:
|
123 |
-
image = tokenizer.draw_bbox_on_latest_picture(response, updated_history)
|
124 |
-
if image is not None:
|
125 |
-
image_path = save_image(image)
|
126 |
-
_chatbot[-1] = (_parse_text(chat_query), (image_path,))
|
127 |
-
response = process_response(response)
|
128 |
-
else:
|
129 |
-
_chatbot[-1] = (_parse_text(chat_query), response)
|
130 |
else:
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
-
|
134 |
|
135 |
-
return _chatbot
|
136 |
|
137 |
|
138 |
def regenerate(_chatbot, task_history):
|
|
|
108 |
if not _chatbot:
|
109 |
return _chatbot
|
110 |
chat_query = _chatbot[-1][0]
|
111 |
+
if isinstance(chat_query, tuple):
|
112 |
+
print("User uploaded an image.")
|
113 |
+
query = {'image': chat_query[0]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
else:
|
115 |
+
print("User: " + _parse_text(chat_query))
|
116 |
+
query = {'text': chat_query}
|
117 |
+
history_cp = copy.deepcopy(task_history)
|
118 |
+
full_response = ""
|
119 |
+
history = process_history_for_model(history_cp)
|
120 |
+
response, history = model.chat(tokenizer, query=query, history=history)
|
121 |
+
image = tokenizer.draw_bbox_on_latest_picture(response, history)
|
122 |
+
if image is not None:
|
123 |
+
image_path = save_image(image)
|
124 |
+
_chatbot[-1] = (chat_query, (image_path,))
|
125 |
+
response = process_response(response)
|
126 |
+
else:
|
127 |
+
_chatbot[-1] = (chat_query, response)
|
128 |
+
task_history = update_task_history(task_history, history, response)
|
129 |
|
130 |
+
return _chatbot
|
131 |
|
|
|
132 |
|
133 |
|
134 |
def regenerate(_chatbot, task_history):
|