Keyven commited on
Commit
a076c9d
β€’
1 Parent(s): 6ec5f0d

Update perf.

Browse files
Files changed (1) hide show
  1. app.py +18 -33
app.py CHANGED
@@ -119,25 +119,6 @@ def handle_regeneration(chatbot, task_history):
119
  print("After:", task_history, chatbot)
120
  return get_chat_response(chatbot, task_history)
121
 
122
- chatbot = []
123
- task_history = []
124
-
125
- def main_function(text, image):
126
- global chatbot, task_history
127
- if text:
128
- chatbot, task_history = handle_text_input(chatbot, task_history, text)
129
- if image:
130
- chatbot, task_history = handle_file_upload(chatbot, task_history, image)
131
- chatbot, task_history = get_chat_response(chatbot, task_history)
132
- formatted_response = chatbot[-1][1] # Get the latest response from the chatbot
133
- return formatted_response
134
-
135
- def clear_history_fn():
136
- global chatbot, task_history
137
- chatbot.clear()
138
- task_history.clear()
139
- return "History cleared."
140
-
141
  # Custom CSS
142
  css = '''
143
  .gradio-container {
@@ -152,21 +133,25 @@ with gr.Blocks(css=css) as demo:
152
  "Special thanks to [@Artificialguybr](https://twitter.com/artificialguybr) for the inspiration from his code.\n"
153
  "### Qwen-VL: A Multimodal Large Vision Language Model by Alibaba Cloud\n"
154
  )
155
- chat_interface = gr.Interface(
156
- fn=main_function,
157
- inputs=[
158
- gr.components.Textbox(lines=2, label='Input'), # Update here
159
- gr.components.Image(type='filepath', label='Upload Image') # Update here
160
- ],
161
- outputs='text',
162
- live=True,
163
- layout='vertical',
164
- theme=None,
165
- css=css
166
- ).launch()
167
- gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
168
 
169
- demo.add_button("🧹 Clear History", clear_history_fn)
 
 
 
 
 
 
 
 
170
 
171
  demo.launch(share=True)
172
 
 
119
  print("After:", task_history, chatbot)
120
  return get_chat_response(chatbot, task_history)
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  # Custom CSS
123
  css = '''
124
  .gradio-container {
 
133
  "Special thanks to [@Artificialguybr](https://twitter.com/artificialguybr) for the inspiration from his code.\n"
134
  "### Qwen-VL: A Multimodal Large Vision Language Model by Alibaba Cloud\n"
135
  )
136
+ chatbot = gr.Chatbot(label='Qwen-VL-Chat', elem_classes="control-height", height=520)
137
+ query = gr.Textbox(lines=2, label='Input')
138
+ task_history = gr.State([])
139
+
140
+ with gr.Row():
141
+ upload_btn = gr.UploadButton("πŸ“ Upload", file_types=["image"])
142
+ submit_btn = gr.Button("πŸš€ Submit")
143
+ regen_btn = gr.Button("πŸ€”οΈ Regenerate")
144
+ clear_btn = gr.Button("🧹 Clear History")
 
 
 
 
145
 
146
+ gr.Markdown("### Key Features:\n- **Strong Performance**: Surpasses existing LVLMs on multiple English benchmarks including Zero-shot Captioning and VQA.\n- **Multi-lingual Support**: Supports English, Chinese, and multi-lingual conversation.\n- **High Resolution**: Utilizes 448*448 resolution for fine-grained recognition and understanding.")
147
+ submit_btn.click(handle_text_input, [chatbot, task_history, query], [chatbot, task_history]).then(
148
+ get_chat_response, [chatbot, task_history], [chatbot], show_progress=True
149
+ )
150
+ submit_btn.click(clear_input, [], [query])
151
+ clear_btn.click(clear_history, [task_history], [chatbot], show_progress=True)
152
+ regen_btn.click(handle_regeneration, [chatbot, task_history], [chatbot], show_progress=True)
153
+ upload_btn.upload(handle_file_upload, [chatbot, task_history, upload_btn], [chatbot, task_history], show_progress=True)
154
+
155
 
156
  demo.launch(share=True)
157