GiantPandas commited on
Commit
f069167
·
verified ·
1 Parent(s): df79f9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -134,23 +134,24 @@ def _launch_demo(args):
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
- messages.append({'role': 'assistant', 'content': [{"type": "text", 'text': a}]})
151
- content = []
152
- else:
153
  continue
 
 
 
 
 
 
 
 
154
 
155
  messages.pop()
156
  responses = client.chat.completions.create(
 
134
  messages = []
135
  content = []
136
  for q, a in history_cp:
137
+ # ---------- 组装 user content ----------
138
+ if isinstance(q, (tuple, list)):
139
+ user_content = [{"type": "video_url" if is_video_file(q[0]) else "image_url",
140
+ "video_url" if is_video_file(q[0]) else "image_url":
141
+ {"url": f"file://{q[0]}"} if is_video_file(q[0])
142
+ else {"url": f"data:image/jpeg;base64,{encode_image(q[0])}"}}]
143
+ elif q and q.strip(): # 非空文本
144
+ user_content = [{"type": "text", "text": q}]
145
+ else: # 空串 → 跳过
 
 
 
 
 
 
 
146
  continue
147
+
148
+ messages.append({"role": "user", "content": user_content})
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(