ClownRat commited on
Commit
2741ec8
·
1 Parent(s): d15f44e

update multi-turn image or video showing.

Browse files
Files changed (1) hide show
  1. app.py +19 -16
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
- previous_image = re.findall(r'<img src="./file=(.+?)"', chatbot[0][0])
133
- previous_video = re.findall(r'<video controls playsinline width="500" style="display: inline-block;" src="./file=(.+?)"', chatbot[0][0])
134
- print(image, video)
135
- print(previous_image, previous_video)
136
- if len(previous_image) > 0:
137
- previous_image = previous_image[0]
138
- # 2.1 new image append or pure text input will start a new conversation
139
- if image is not None and os.path.basename(previous_image) != os.path.basename(image):
140
- message.clear()
141
- one_turn_chat[0] += "\n" + show_images
142
- elif len(previous_video) > 0:
143
- previous_video = previous_video[0]
144
- # 2.2 new video append or pure text input will start a new conversation
145
- if video is not None and os.path.basename(previous_video) != os.path.basename(video):
146
- message.clear()
147
- one_turn_chat[0] += "\n" + show_images
 
 
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)