Spaces:
Runtime error
Runtime error
Vision-CAIR
commited on
Commit
Β·
c3ad99f
1
Parent(s):
eafe020
Update app.py
Browse files
app.py
CHANGED
@@ -380,11 +380,13 @@ def visualize_all_bbox_together(image, generation):
|
|
380 |
return pil_image, generation_colored
|
381 |
|
382 |
|
383 |
-
def gradio_reset(chat_state, img_list):
|
384 |
if chat_state is not None:
|
385 |
chat_state.messages = []
|
386 |
if img_list is not None:
|
387 |
img_list = []
|
|
|
|
|
388 |
return None, gr.update(value=None, interactive=True), gr.update(placeholder='Upload your image and chat',
|
389 |
interactive=True), chat_state, img_list
|
390 |
|
@@ -481,7 +483,7 @@ def gradio_stream_answer(chatbot, chat_state, img_list, temperature):
|
|
481 |
return chatbot, chat_state
|
482 |
|
483 |
|
484 |
-
def gradio_visualize(chatbot, gr_img):
|
485 |
if isinstance(gr_img, dict):
|
486 |
gr_img, mask = gr_img['image'], gr_img['mask']
|
487 |
|
@@ -491,6 +493,7 @@ def gradio_visualize(chatbot, gr_img):
|
|
491 |
if len(generation_color):
|
492 |
chatbot[-1][1] = generation_color
|
493 |
file_path = save_tmp_img(visual_img)
|
|
|
494 |
chatbot = chatbot + [[None, (file_path,)]]
|
495 |
|
496 |
return chatbot
|
@@ -579,6 +582,7 @@ with gr.Blocks() as demo:
|
|
579 |
|
580 |
upload_flag = gr.State(value=0)
|
581 |
replace_flag = gr.State(value=0)
|
|
|
582 |
image.upload(image_upload_trigger, [upload_flag, replace_flag, img_list], [upload_flag, replace_flag])
|
583 |
|
584 |
with gr.Row():
|
@@ -623,8 +627,8 @@ with gr.Blocks() as demo:
|
|
623 |
[chatbot, chat_state]
|
624 |
).success(
|
625 |
gradio_visualize,
|
626 |
-
[chatbot, image],
|
627 |
-
[chatbot],
|
628 |
queue=False,
|
629 |
)
|
630 |
|
@@ -638,10 +642,10 @@ with gr.Blocks() as demo:
|
|
638 |
[chatbot, chat_state]
|
639 |
).success(
|
640 |
gradio_visualize,
|
641 |
-
[chatbot, image],
|
642 |
-
[chatbot],
|
643 |
)
|
644 |
|
645 |
-
clear.click(gradio_reset, [chat_state, img_list], [chatbot, image, text_input, chat_state, img_list], queue=False)
|
646 |
|
647 |
demo.launch(enable_queue=True)
|
|
|
380 |
return pil_image, generation_colored
|
381 |
|
382 |
|
383 |
+
def gradio_reset(chat_state, img_list, path_list):
|
384 |
if chat_state is not None:
|
385 |
chat_state.messages = []
|
386 |
if img_list is not None:
|
387 |
img_list = []
|
388 |
+
for path in path_list:
|
389 |
+
os.remove(path)
|
390 |
return None, gr.update(value=None, interactive=True), gr.update(placeholder='Upload your image and chat',
|
391 |
interactive=True), chat_state, img_list
|
392 |
|
|
|
483 |
return chatbot, chat_state
|
484 |
|
485 |
|
486 |
+
def gradio_visualize(chatbot, gr_img, path_list):
|
487 |
if isinstance(gr_img, dict):
|
488 |
gr_img, mask = gr_img['image'], gr_img['mask']
|
489 |
|
|
|
493 |
if len(generation_color):
|
494 |
chatbot[-1][1] = generation_color
|
495 |
file_path = save_tmp_img(visual_img)
|
496 |
+
path_list.append(file_path)
|
497 |
chatbot = chatbot + [[None, (file_path,)]]
|
498 |
|
499 |
return chatbot
|
|
|
582 |
|
583 |
upload_flag = gr.State(value=0)
|
584 |
replace_flag = gr.State(value=0)
|
585 |
+
path_list = gr.State(value=0)
|
586 |
image.upload(image_upload_trigger, [upload_flag, replace_flag, img_list], [upload_flag, replace_flag])
|
587 |
|
588 |
with gr.Row():
|
|
|
627 |
[chatbot, chat_state]
|
628 |
).success(
|
629 |
gradio_visualize,
|
630 |
+
[chatbot, image, path_list],
|
631 |
+
[chatbot, path_list],
|
632 |
queue=False,
|
633 |
)
|
634 |
|
|
|
642 |
[chatbot, chat_state]
|
643 |
).success(
|
644 |
gradio_visualize,
|
645 |
+
[chatbot, image, path_list],
|
646 |
+
[chatbot, path_list],
|
647 |
)
|
648 |
|
649 |
+
clear.click(gradio_reset, [chat_state, img_list, path_list], [chatbot, image, text_input, chat_state, img_list], queue=False)
|
650 |
|
651 |
demo.launch(enable_queue=True)
|