Spaces:
Runtime error
Runtime error
update chat
Browse files- app.py +4 -2
- multimodal/open_flamingo/chat/conversation.py +5 -4
app.py
CHANGED
@@ -207,11 +207,12 @@ def gradio_reset(chat_state, img_list):
|
|
207 |
value="Upload & Start Chat", interactive=True), chat_state, img_list
|
208 |
|
209 |
|
210 |
-
def upload_img(gr_img, text_input, chat_state):
|
211 |
if gr_img is None:
|
212 |
return None, None, gr.update(interactive=True), chat_state, None
|
213 |
chat_state = []
|
214 |
img_list = []
|
|
|
215 |
llm_message = chat.upload_img(gr_img, chat_state, img_list)
|
216 |
return gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(
|
217 |
value="Start Chatting", interactive=False), chat_state, img_list
|
@@ -221,6 +222,7 @@ def gradio_ask(user_message, chatbot, chat_state):
|
|
221 |
if len(user_message) == 0:
|
222 |
return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state
|
223 |
|
|
|
224 |
chat.ask(user_message, chat_state)
|
225 |
chatbot = chatbot + [[user_message, None]]
|
226 |
return '', chatbot, chat_state
|
@@ -271,7 +273,7 @@ with gr.Blocks() as demo:
|
|
271 |
chatbot = gr.Chatbot(label='Compositional-VLM')
|
272 |
text_input = gr.Textbox(label='User', placeholder='Please upload your image first', interactive=False)
|
273 |
|
274 |
-
upload_button.click(upload_img, [image, text_input, chat_state],
|
275 |
[image, text_input, upload_button, chat_state, img_list])
|
276 |
|
277 |
text_input.submit(gradio_ask, [text_input, chatbot, chat_state], [text_input, chatbot, chat_state]).then(
|
|
|
207 |
value="Upload & Start Chat", interactive=True), chat_state, img_list
|
208 |
|
209 |
|
210 |
+
def upload_img(gr_img, text_input, chat_state,chatbot):
|
211 |
if gr_img is None:
|
212 |
return None, None, gr.update(interactive=True), chat_state, None
|
213 |
chat_state = []
|
214 |
img_list = []
|
215 |
+
chatbot = chatbot + [[gr_img, None]]
|
216 |
llm_message = chat.upload_img(gr_img, chat_state, img_list)
|
217 |
return gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(
|
218 |
value="Start Chatting", interactive=False), chat_state, img_list
|
|
|
222 |
if len(user_message) == 0:
|
223 |
return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state
|
224 |
|
225 |
+
|
226 |
chat.ask(user_message, chat_state)
|
227 |
chatbot = chatbot + [[user_message, None]]
|
228 |
return '', chatbot, chat_state
|
|
|
273 |
chatbot = gr.Chatbot(label='Compositional-VLM')
|
274 |
text_input = gr.Textbox(label='User', placeholder='Please upload your image first', interactive=False)
|
275 |
|
276 |
+
upload_button.click(upload_img, [image, text_input, chat_state,chatbot],
|
277 |
[image, text_input, upload_button, chat_state, img_list])
|
278 |
|
279 |
text_input.submit(gradio_ask, [text_input, chatbot, chat_state], [text_input, chatbot, chat_state]).then(
|
multimodal/open_flamingo/chat/conversation.py
CHANGED
@@ -317,14 +317,15 @@ class Chat:
|
|
317 |
visual_token_id = self.tokenizer("<|#visual#|>", add_special_tokens=False)["input_ids"][-1]
|
318 |
previsual_token_id = self.tokenizer("<|#previsual#|>", add_special_tokens=False)["input_ids"][-1]
|
319 |
prebox_token_id = self.tokenizer("<|#prebox#|>", add_special_tokens=False)["input_ids"][-1]
|
320 |
-
size =
|
321 |
model.eval()
|
322 |
# "/gpfs/u/home/LMCG/LMCGljnn/scratch-shared/cdl/tmp_img/chat_vis/chat19.png"
|
323 |
-
image_path = input("Please enter the image path: ")
|
324 |
-
image =
|
325 |
image = image.resize((size, size))
|
326 |
print(f"image size: {image.size}")
|
327 |
-
batch_images = preprocess_image(
|
|
|
328 |
# conversation = []
|
329 |
human_sentence = None
|
330 |
conv.append({
|
|
|
317 |
visual_token_id = self.tokenizer("<|#visual#|>", add_special_tokens=False)["input_ids"][-1]
|
318 |
previsual_token_id = self.tokenizer("<|#previsual#|>", add_special_tokens=False)["input_ids"][-1]
|
319 |
prebox_token_id = self.tokenizer("<|#prebox#|>", add_special_tokens=False)["input_ids"][-1]
|
320 |
+
size = 224
|
321 |
model.eval()
|
322 |
# "/gpfs/u/home/LMCG/LMCGljnn/scratch-shared/cdl/tmp_img/chat_vis/chat19.png"
|
323 |
+
# image_path = input("Please enter the image path: ")
|
324 |
+
image = img_list[0].convert("RGB")
|
325 |
image = image.resize((size, size))
|
326 |
print(f"image size: {image.size}")
|
327 |
+
batch_images = preprocess_image(image, self.vis_processor).unsqueeze(0).unsqueeze(1).unsqueeze(0)
|
328 |
+
|
329 |
# conversation = []
|
330 |
human_sentence = None
|
331 |
conv.append({
|