Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,12 @@ def generate_response(message, history, thinking_mode):
|
|
| 28 |
if isinstance(user_msg, str):
|
| 29 |
user_content = [{"type": "text", "text": user_msg}]
|
| 30 |
else:
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
user_content = []
|
| 33 |
img_paths = file_paths if isinstance(file_paths, list) else []
|
| 34 |
for path in img_paths:
|
|
@@ -49,14 +54,14 @@ def generate_response(message, history, thinking_mode):
|
|
| 49 |
# Current user message
|
| 50 |
if isinstance(message, str):
|
| 51 |
curr_text = message
|
| 52 |
-
|
| 53 |
else:
|
| 54 |
curr_text = message.get('text', '')
|
| 55 |
curr_files = message.get('files', [])
|
|
|
|
| 56 |
curr_user_content = []
|
| 57 |
curr_images = []
|
| 58 |
-
for
|
| 59 |
-
path = f['path']
|
| 60 |
if path.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
| 61 |
try:
|
| 62 |
img = Image.open(path)
|
|
@@ -104,7 +109,7 @@ def generate_response(message, history, thinking_mode):
|
|
| 104 |
)
|
| 105 |
|
| 106 |
# Prepare display for current user message
|
| 107 |
-
user_display = curr_text if not
|
| 108 |
new_history = history + [(user_display, output_text)]
|
| 109 |
|
| 110 |
return "", new_history
|
|
|
|
| 28 |
if isinstance(user_msg, str):
|
| 29 |
user_content = [{"type": "text", "text": user_msg}]
|
| 30 |
else:
|
| 31 |
+
if isinstance(user_msg, tuple):
|
| 32 |
+
text, file_paths = user_msg
|
| 33 |
+
else:
|
| 34 |
+
text = user_msg.get('text', '')
|
| 35 |
+
files = user_msg.get('files', [])
|
| 36 |
+
file_paths = [f['path'] if isinstance(f, dict) else f for f in files]
|
| 37 |
user_content = []
|
| 38 |
img_paths = file_paths if isinstance(file_paths, list) else []
|
| 39 |
for path in img_paths:
|
|
|
|
| 54 |
# Current user message
|
| 55 |
if isinstance(message, str):
|
| 56 |
curr_text = message
|
| 57 |
+
curr_file_paths = []
|
| 58 |
else:
|
| 59 |
curr_text = message.get('text', '')
|
| 60 |
curr_files = message.get('files', [])
|
| 61 |
+
curr_file_paths = [f['path'] if isinstance(f, dict) else f for f in curr_files]
|
| 62 |
curr_user_content = []
|
| 63 |
curr_images = []
|
| 64 |
+
for path in curr_file_paths:
|
|
|
|
| 65 |
if path.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
| 66 |
try:
|
| 67 |
img = Image.open(path)
|
|
|
|
| 109 |
)
|
| 110 |
|
| 111 |
# Prepare display for current user message
|
| 112 |
+
user_display = curr_text if not curr_file_paths else (curr_text, curr_file_paths)
|
| 113 |
new_history = history + [(user_display, output_text)]
|
| 114 |
|
| 115 |
return "", new_history
|