comidan commited on
Commit
925216a
1 Parent(s): dfcbabb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -92,19 +92,33 @@ def upload_imgorvideo(gr_video, gr_img, text_input, chat_state,chatbot,audio_fla
92
  elif gr_img is not None and gr_video is None:
93
  print(gr_img)
94
  chatbot = chatbot + [((gr_img,), None)]
95
- chat_state.system = "You are able to understand the visual content that the user provides. Follow the instructions carefully and explain your answers in detail."
 
 
 
 
 
 
 
 
96
  img_list = []
97
  llm_message = chat.upload_img(gr_img, chat_state, img_list)
98
  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
99
  elif gr_video is not None and gr_img is None:
100
  print(gr_video)
101
  chatbot = chatbot + [((gr_video,), None)]
102
- chat_state.system = ""
 
 
 
 
 
 
 
 
 
103
  img_list = []
104
- if audio_flag:
105
- llm_message = chat.upload_video(gr_video, chat_state, img_list)
106
- else:
107
- llm_message = chat.upload_video_without_audio(gr_video, chat_state, img_list)
108
  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
109
  else:
110
  # img_list = []
@@ -121,15 +135,16 @@ def gradio_ask(user_message, chatbot, chat_state):
121
  def gradio_answer(chatbot, chat_state, img_list, num_beams, temperature):
122
  llm_message = chat.answer(conv=chat_state,
123
  img_list=img_list,
124
- num_beams=num_beams,
125
  temperature=temperature,
126
- max_new_tokens=300,
127
- max_length=2000)[0]
128
  chatbot[-1][1] = llm_message
129
  print(chat_state.get_prompt())
130
  print(chat_state)
131
  return chatbot, chat_state, img_list
132
 
 
133
  title = """
134
  <h1 align="center"><a href="https://github.com/DAMO-NLP-SG/Video-LLaMA"><img src="https://s1.ax1x.com/2023/05/22/p9oQ0FP.jpg", alt="Video-LLaMA" border="0" style="margin: 0 auto; height: 200px;" /></a> </h1>
135
 
 
92
  elif gr_img is not None and gr_video is None:
93
  print(gr_img)
94
  chatbot = chatbot + [((gr_img,), None)]
95
+ chat_state = Conversation(
96
+ system= "You are able to understand the visual content that the user provides."
97
+ "Follow the instructions carefully and explain your answers in detail.",
98
+ roles=("Human", "Assistant"),
99
+ messages=[],
100
+ offset=0,
101
+ sep_style=SeparatorStyle.SINGLE,
102
+ sep="###",
103
+ )
104
  img_list = []
105
  llm_message = chat.upload_img(gr_img, chat_state, img_list)
106
  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
107
  elif gr_video is not None and gr_img is None:
108
  print(gr_video)
109
  chatbot = chatbot + [((gr_video,), None)]
110
+ chat_state = default_conversation.copy()
111
+ chat_state = Conversation(
112
+ system= "You are able to understand the visual content that the user provides."
113
+ "Follow the instructions carefully and explain your answers in detail.",
114
+ roles=("Human", "Assistant"),
115
+ messages=[],
116
+ offset=0,
117
+ sep_style=SeparatorStyle.SINGLE,
118
+ sep="###",
119
+ )
120
  img_list = []
121
+ llm_message = chat.upload_video(gr_video, chat_state, img_list)
 
 
 
122
  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
123
  else:
124
  # img_list = []
 
135
  def gradio_answer(chatbot, chat_state, img_list, num_beams, temperature):
136
  llm_message = chat.answer(conv=chat_state,
137
  img_list=img_list,
138
+ num_beams=1,
139
  temperature=temperature,
140
+ max_new_tokens=240,
141
+ max_length=511)[0]
142
  chatbot[-1][1] = llm_message
143
  print(chat_state.get_prompt())
144
  print(chat_state)
145
  return chatbot, chat_state, img_list
146
 
147
+
148
  title = """
149
  <h1 align="center"><a href="https://github.com/DAMO-NLP-SG/Video-LLaMA"><img src="https://s1.ax1x.com/2023/05/22/p9oQ0FP.jpg", alt="Video-LLaMA" border="0" style="margin: 0 auto; height: 200px;" /></a> </h1>
150