Update app.py
Browse files
app.py
CHANGED
|
@@ -149,15 +149,17 @@ def predict(_chatbot, task_history) -> tuple:
|
|
| 149 |
if image is not None:
|
| 150 |
image_path = save_image(image, uploaded_file_dir)
|
| 151 |
_chatbot[-1] = (chat_query, (image_path,))
|
|
|
|
| 152 |
else:
|
| 153 |
_chatbot[-1] = (chat_query, response) # Make sure this is a tuple of two elements
|
|
|
|
| 154 |
else:
|
| 155 |
_chatbot[-1] = (chat_query, response)
|
| 156 |
-
|
| 157 |
-
task_history[-1] = _chatbot[-1]
|
| 158 |
|
| 159 |
return _chatbot, task_history
|
| 160 |
|
|
|
|
| 161 |
def save_uploaded_image(image_file, upload_dir):
|
| 162 |
if image is None:
|
| 163 |
return None
|
|
@@ -185,14 +187,20 @@ def regenerate(_chatbot, task_history) -> list:
|
|
| 185 |
|
| 186 |
def add_text(history, task_history, text) -> tuple:
|
| 187 |
if not text.strip():
|
| 188 |
-
return history, task_history,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
task_text = text
|
| 190 |
if len(text) >= 2 and text[-1] in PUNCTUATION and text[-2] not in PUNCTUATION:
|
| 191 |
task_text = text[:-1]
|
| 192 |
history_item = (_parse_text(task_text), None)
|
| 193 |
history.append(history_item)
|
| 194 |
task_history.append(history_item)
|
| 195 |
-
return history, task_history,
|
| 196 |
|
| 197 |
def add_file(history, task_history, file):
|
| 198 |
if file is None:
|
|
|
|
| 149 |
if image is not None:
|
| 150 |
image_path = save_image(image, uploaded_file_dir)
|
| 151 |
_chatbot[-1] = (chat_query, (image_path,))
|
| 152 |
+
task_history[-1] = (chat_query, image_path)
|
| 153 |
else:
|
| 154 |
_chatbot[-1] = (chat_query, response) # Make sure this is a tuple of two elements
|
| 155 |
+
task_history[-1] = (chat_query, response)
|
| 156 |
else:
|
| 157 |
_chatbot[-1] = (chat_query, response)
|
| 158 |
+
task_history[-1] = (chat_query, response)
|
|
|
|
| 159 |
|
| 160 |
return _chatbot, task_history
|
| 161 |
|
| 162 |
+
|
| 163 |
def save_uploaded_image(image_file, upload_dir):
|
| 164 |
if image is None:
|
| 165 |
return None
|
|
|
|
| 187 |
|
| 188 |
def add_text(history, task_history, text) -> tuple:
|
| 189 |
if not text.strip():
|
| 190 |
+
return history, task_history, chatbot
|
| 191 |
+
if not any(isinstance(item[0], tuple) for item in history):
|
| 192 |
+
prompt = "Please upload and submit an image to get started."
|
| 193 |
+
history.append((prompt, None))
|
| 194 |
+
task_history.append((prompt, None))
|
| 195 |
+
chatbot.append(prompt)
|
| 196 |
+
return history, task_history, chatbot
|
| 197 |
task_text = text
|
| 198 |
if len(text) >= 2 and text[-1] in PUNCTUATION and text[-2] not in PUNCTUATION:
|
| 199 |
task_text = text[:-1]
|
| 200 |
history_item = (_parse_text(task_text), None)
|
| 201 |
history.append(history_item)
|
| 202 |
task_history.append(history_item)
|
| 203 |
+
return history, task_history, chatbot
|
| 204 |
|
| 205 |
def add_file(history, task_history, file):
|
| 206 |
if file is None:
|