Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -48,25 +48,29 @@ class ChatBot:
|
|
48 |
else:
|
49 |
return None
|
50 |
|
|
|
|
|
|
|
51 |
def clear_memory(self):
|
52 |
if torch.cuda.is_available():
|
53 |
torch.cuda.empty_cache()
|
54 |
gc.collect()
|
55 |
|
56 |
-
def chat_interface(
|
|
|
57 |
image_path = file.name if file is not None else None
|
58 |
response = chatbot.chat(image_path=image_path, text_query=text_query)
|
|
|
59 |
if "<box>" in response:
|
60 |
image_with_boxes = chatbot.draw_boxes(response)
|
|
|
61 |
chatbot.clear_memory()
|
62 |
-
text_response = re.sub(r'<ref>.*?</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', '', response).strip()
|
63 |
return [("Qwen-VL_Chat", text_response), ("Qwen-VL_Image", image_with_boxes)]
|
64 |
else:
|
65 |
chatbot.clear_memory()
|
66 |
return [("Qwen-VL_Chat", response)]
|
67 |
-
|
68 |
with gr.Blocks() as demo:
|
69 |
-
chatbot = ChatBot()
|
70 |
gr.Markdown("""
|
71 |
# 🙋🏻♂️欢迎来到🌟Tonic 的🦆Qwen-VL-Chat🤩Bot!🚀
|
72 |
# 🙋🏻♂️Welcome to Tonic's🦆Qwen-VL-Chat🤩Bot!🚀
|
@@ -87,7 +91,7 @@ Join us: TeamTonic is always making cool demos! Join our active builder's comm
|
|
87 |
|
88 |
submit_btn.click(
|
89 |
fn=chat_interface,
|
90 |
-
inputs=[
|
91 |
outputs=[chatbot_component]
|
92 |
)
|
93 |
gr.Markdown("""
|
|
|
48 |
else:
|
49 |
return None
|
50 |
|
51 |
+
def clean_response(self, response):
|
52 |
+
return re.sub(r'<ref>(.*?)</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', r'\1', response).strip()
|
53 |
+
|
54 |
def clear_memory(self):
|
55 |
if torch.cuda.is_available():
|
56 |
torch.cuda.empty_cache()
|
57 |
gc.collect()
|
58 |
|
59 |
+
def chat_interface(text_query, file):
|
60 |
+
chatbot = ChatBot()
|
61 |
image_path = file.name if file is not None else None
|
62 |
response = chatbot.chat(image_path=image_path, text_query=text_query)
|
63 |
+
|
64 |
if "<box>" in response:
|
65 |
image_with_boxes = chatbot.draw_boxes(response)
|
66 |
+
text_response = chatbot.clean_response(response)
|
67 |
chatbot.clear_memory()
|
|
|
68 |
return [("Qwen-VL_Chat", text_response), ("Qwen-VL_Image", image_with_boxes)]
|
69 |
else:
|
70 |
chatbot.clear_memory()
|
71 |
return [("Qwen-VL_Chat", response)]
|
72 |
+
|
73 |
with gr.Blocks() as demo:
|
|
|
74 |
gr.Markdown("""
|
75 |
# 🙋🏻♂️欢迎来到🌟Tonic 的🦆Qwen-VL-Chat🤩Bot!🚀
|
76 |
# 🙋🏻♂️Welcome to Tonic's🦆Qwen-VL-Chat🤩Bot!🚀
|
|
|
91 |
|
92 |
submit_btn.click(
|
93 |
fn=chat_interface,
|
94 |
+
inputs=[query, file_upload],
|
95 |
outputs=[chatbot_component]
|
96 |
)
|
97 |
gr.Markdown("""
|