Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,24 +134,26 @@ def _launch_demo(args):
|
|
| 134 |
messages = []
|
| 135 |
content = []
|
| 136 |
for q, a in history_cp:
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
continue
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
if a: # 只有当 a 不为 None / 空串 时才加入
|
| 151 |
-
messages.append(
|
| 152 |
-
{"role": "assistant",
|
| 153 |
-
"content": [{"type": "text", "text": a}]}
|
| 154 |
-
)
|
| 155 |
|
| 156 |
messages.pop()
|
| 157 |
responses = client.chat.completions.create(
|
|
|
|
| 134 |
messages = []
|
| 135 |
content = []
|
| 136 |
for q, a in history_cp:
|
| 137 |
+
if isinstance(q, (tuple, list)):
|
| 138 |
+
if is_video_file(q[0]):
|
| 139 |
+
content.append({'video': f'file://{q[0]}'})
|
| 140 |
+
else:
|
| 141 |
+
content.append({
|
| 142 |
+
"type": "image_url",
|
| 143 |
+
"image_url": {
|
| 144 |
+
"url": f"data:image/jpeg;base64,{encode_image(q[0])}"
|
| 145 |
+
}
|
| 146 |
+
})
|
| 147 |
+
elif q and q.strip():
|
| 148 |
+
content.append({"type": "text", 'text': q})
|
| 149 |
+
messages.append({'role': 'user', 'content': content})
|
| 150 |
+
if a:
|
| 151 |
+
messages.append({'role': 'assistant', 'content': [{"type": "text", 'text': a}]})
|
| 152 |
+
content = []
|
| 153 |
+
else:
|
| 154 |
continue
|
| 155 |
+
|
| 156 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
messages.pop()
|
| 159 |
responses = client.chat.completions.create(
|