Spaces:
Running
on
Zero
Running
on
Zero
update multi-turn image or video showing.
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import spaces
|
|
2 |
|
3 |
import os
|
4 |
import re
|
|
|
5 |
|
6 |
import torch
|
7 |
import gradio as gr
|
@@ -129,22 +130,24 @@ def generate(image, video, message, chatbot, textbox_in, temperature, top_p, max
|
|
129 |
one_turn_chat[0] += "\n" + show_images
|
130 |
# 2. not first run case
|
131 |
else:
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
148 |
|
149 |
message.append({'role': 'user', 'content': textbox_in})
|
150 |
text_en_out = handler.generate(data, message, temperature=temperature, top_p=top_p, max_output_tokens=max_output_tokens)
|
|
|
2 |
|
3 |
import os
|
4 |
import re
|
5 |
+
import traceback
|
6 |
|
7 |
import torch
|
8 |
import gradio as gr
|
|
|
130 |
one_turn_chat[0] += "\n" + show_images
|
131 |
# 2. not first run case
|
132 |
else:
|
133 |
+
# scanning the last image or video
|
134 |
+
length = len(chatbot)
|
135 |
+
for i in range(length - 1, -1):
|
136 |
+
previous_image = re.findall(r'<img src="./file=(.+?)"', chatbot[i][0])
|
137 |
+
previous_video = re.findall(r'<video controls playsinline width="500" style="display: inline-block;" src="./file=(.+?)"', chatbot[i][0])
|
138 |
+
|
139 |
+
if len(previous_image) > 0:
|
140 |
+
previous_image = previous_image[-1]
|
141 |
+
# 2.1 new image append or pure text input will start a new conversation
|
142 |
+
if video is not None or (image is not None and os.path.basename(previous_image) != os.path.basename(image)):
|
143 |
+
message.clear()
|
144 |
+
one_turn_chat[0] += "\n" + show_images
|
145 |
+
elif len(previous_video) > 0:
|
146 |
+
previous_video = previous_video[-1]
|
147 |
+
# 2.2 new video append or pure text input will start a new conversation
|
148 |
+
if image is not None or (video is not None and os.path.basename(previous_video) != os.path.basename(video)):
|
149 |
+
message.clear()
|
150 |
+
one_turn_chat[0] += "\n" + show_images
|
151 |
|
152 |
message.append({'role': 'user', 'content': textbox_in})
|
153 |
text_en_out = handler.generate(data, message, temperature=temperature, top_p=top_p, max_output_tokens=max_output_tokens)
|