Spaces:
Runtime error
Runtime error
舟勤
commited on
Commit
·
26986d2
1
Parent(s):
89361cc
test
Browse files
app.py
CHANGED
|
@@ -82,11 +82,12 @@ def gradio_reset(chat_state, img_list):
|
|
| 82 |
img_list = []
|
| 83 |
return None, gr.update(value=None, interactive=True), gr.update(value=None, interactive=True), gr.update(placeholder='Please upload your video first', interactive=False),gr.update(value="Upload & Start Chat", interactive=True), chat_state, img_list
|
| 84 |
|
| 85 |
-
def upload_imgorvideo(gr_video, gr_img, text_input, chat_state):
|
| 86 |
if gr_img is None and gr_video is None:
|
| 87 |
return None, None, None, gr.update(interactive=True), chat_state, None
|
| 88 |
elif gr_img is not None and gr_video is None:
|
| 89 |
print(gr_img)
|
|
|
|
| 90 |
chat_state = Conversation(
|
| 91 |
system= "You are able to understand the visual content that the user provides."
|
| 92 |
"Follow the instructions carefully and explain your answers in detail.",
|
|
@@ -98,9 +99,10 @@ def upload_imgorvideo(gr_video, gr_img, text_input, chat_state):
|
|
| 98 |
)
|
| 99 |
img_list = []
|
| 100 |
llm_message = chat.upload_img(gr_img, chat_state, img_list)
|
| 101 |
-
return gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, img_list
|
| 102 |
elif gr_video is not None and gr_img is None:
|
| 103 |
print(gr_video)
|
|
|
|
| 104 |
chat_state = default_conversation.copy()
|
| 105 |
chat_state = Conversation(
|
| 106 |
system= "You are able to understand the visual content that the user provides."
|
|
@@ -113,10 +115,10 @@ def upload_imgorvideo(gr_video, gr_img, text_input, chat_state):
|
|
| 113 |
)
|
| 114 |
img_list = []
|
| 115 |
llm_message = chat.upload_video(gr_video, chat_state, img_list)
|
| 116 |
-
return gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, img_list
|
| 117 |
else:
|
| 118 |
# img_list = []
|
| 119 |
-
return gr.update(interactive=False), gr.update(interactive=False, placeholder='Currently, only one input is supported'), gr.update(value="Currently, only one input is supported", interactive=False), chat_state, None
|
| 120 |
|
| 121 |
def gradio_ask(user_message, chatbot, chat_state):
|
| 122 |
if len(user_message) == 0:
|
|
@@ -186,6 +188,10 @@ If you find our project useful, hope you can star our repo and cite our paper as
|
|
| 186 |
}
|
| 187 |
""")
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
#TODO show examples below
|
| 190 |
|
| 191 |
with gr.Blocks() as demo:
|
|
@@ -195,6 +201,7 @@ with gr.Blocks() as demo:
|
|
| 195 |
with gr.Column(scale=0.5):
|
| 196 |
video = gr.Video()
|
| 197 |
image = gr.Image(type="pil")
|
|
|
|
| 198 |
|
| 199 |
upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
|
| 200 |
clear = gr.Button("Restart")
|
|
@@ -240,7 +247,7 @@ with gr.Blocks() as demo:
|
|
| 240 |
], inputs=[video, text_input])
|
| 241 |
|
| 242 |
gr.Markdown(cite_markdown)
|
| 243 |
-
upload_button.click(upload_imgorvideo, [video, image, text_input, chat_state], [video, image, text_input, upload_button, chat_state, img_list])
|
| 244 |
|
| 245 |
text_input.submit(gradio_ask, [text_input, chatbot, chat_state], [text_input, chatbot, chat_state]).then(
|
| 246 |
gradio_answer, [chatbot, chat_state, img_list, num_beams, temperature], [chatbot, chat_state, img_list]
|
|
|
|
| 82 |
img_list = []
|
| 83 |
return None, gr.update(value=None, interactive=True), gr.update(value=None, interactive=True), gr.update(placeholder='Please upload your video first', interactive=False),gr.update(value="Upload & Start Chat", interactive=True), chat_state, img_list
|
| 84 |
|
| 85 |
+
def upload_imgorvideo(gr_video, gr_img, text_input, chat_state,chatbot):
|
| 86 |
if gr_img is None and gr_video is None:
|
| 87 |
return None, None, None, gr.update(interactive=True), chat_state, None
|
| 88 |
elif gr_img is not None and gr_video is None:
|
| 89 |
print(gr_img)
|
| 90 |
+
chatbot = chatbot + [((gr_img,), None)]
|
| 91 |
chat_state = Conversation(
|
| 92 |
system= "You are able to understand the visual content that the user provides."
|
| 93 |
"Follow the instructions carefully and explain your answers in detail.",
|
|
|
|
| 99 |
)
|
| 100 |
img_list = []
|
| 101 |
llm_message = chat.upload_img(gr_img, chat_state, img_list)
|
| 102 |
+
return gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, img_list,chatbot
|
| 103 |
elif gr_video is not None and gr_img is None:
|
| 104 |
print(gr_video)
|
| 105 |
+
chatbot = chatbot + [((gr_video,), None)]
|
| 106 |
chat_state = default_conversation.copy()
|
| 107 |
chat_state = Conversation(
|
| 108 |
system= "You are able to understand the visual content that the user provides."
|
|
|
|
| 115 |
)
|
| 116 |
img_list = []
|
| 117 |
llm_message = chat.upload_video(gr_video, chat_state, img_list)
|
| 118 |
+
return gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, img_list,chatbot
|
| 119 |
else:
|
| 120 |
# img_list = []
|
| 121 |
+
return gr.update(interactive=False), gr.update(interactive=False, placeholder='Currently, only one input is supported'), gr.update(value="Currently, only one input is supported", interactive=False), chat_state, None,chatbot
|
| 122 |
|
| 123 |
def gradio_ask(user_message, chatbot, chat_state):
|
| 124 |
if len(user_message) == 0:
|
|
|
|
| 188 |
}
|
| 189 |
""")
|
| 190 |
|
| 191 |
+
case_note_upload = ("""
|
| 192 |
+
We provide some examples at the bottom of the page. Simply click on them to try them out directly.
|
| 193 |
+
""")
|
| 194 |
+
|
| 195 |
#TODO show examples below
|
| 196 |
|
| 197 |
with gr.Blocks() as demo:
|
|
|
|
| 201 |
with gr.Column(scale=0.5):
|
| 202 |
video = gr.Video()
|
| 203 |
image = gr.Image(type="pil")
|
| 204 |
+
gr.Markdown(case_note_upload)
|
| 205 |
|
| 206 |
upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
|
| 207 |
clear = gr.Button("Restart")
|
|
|
|
| 247 |
], inputs=[video, text_input])
|
| 248 |
|
| 249 |
gr.Markdown(cite_markdown)
|
| 250 |
+
upload_button.click(upload_imgorvideo, [video, image, text_input, chat_state,chatbot], [video, image, text_input, upload_button, chat_state, img_list,chatbot])
|
| 251 |
|
| 252 |
text_input.submit(gradio_ask, [text_input, chatbot, chat_state], [text_input, chatbot, chat_state]).then(
|
| 253 |
gradio_answer, [chatbot, chat_state, img_list, num_beams, temperature], [chatbot, chat_state, img_list]
|