j commited on
Commit
4bbc7e3
Β·
1 Parent(s): 12bd81d

changed modelscope widgets to gradio widgets

Browse files
Files changed (1) hide show
  1. demo/web_demo_audio.py +42 -15
demo/web_demo_audio.py CHANGED
@@ -115,26 +115,53 @@ def _launch_demo(args):
115
  Qwen2-Audio-Instruct <a href="https://modelscope.cn/models/qwen/Qwen2-Audio-7B-Instruct">πŸ€– </a> |
116
  <a href="https://huggingface.co/Qwen/Qwen2-Audio-7B-Instruct">πŸ€—</a>&nbsp |
117
  &nbsp<a href="https://github.com/QwenLM/Qwen2-Audio">Github</a></center>""")
118
- chatbot = mgr.Chatbot(label='Qwen2-Audio-7B-Instruct', elem_classes="control-height", height=750)
119
-
120
- user_input = mgr.MultimodalInput(
121
- interactive=True,
122
- sources=['microphone', 'upload'],
123
- submit_button_props=dict(value="πŸš€ Submit (发送)"),
124
- upload_button_props=dict(value="πŸ“ Upload (δΈŠδΌ ζ–‡δ»Ά)", show_progress=True),
125
- )
126
- task_history = gr.State([])
 
 
 
127
 
128
  with gr.Row():
129
- empty_bin = gr.Button("🧹 Clear History (ζΈ…ι™€εŽ†ε²)")
 
130
  regen_btn = gr.Button("πŸ€”οΈ Regenerate (重试)")
131
 
132
- user_input.submit(fn=add_text,
133
- inputs=[chatbot, task_history, user_input],
134
- outputs=[chatbot, task_history, user_input]).then(
135
- predict, [chatbot, task_history], [chatbot, task_history], show_progress=True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  )
137
- empty_bin.click(reset_state, outputs=[chatbot, task_history], show_progress=True)
 
138
  regen_btn.click(regenerate, [chatbot, task_history], [chatbot, task_history], show_progress=True)
139
 
140
  demo.queue().launch(
 
115
  Qwen2-Audio-Instruct <a href="https://modelscope.cn/models/qwen/Qwen2-Audio-7B-Instruct">πŸ€– </a> |
116
  <a href="https://huggingface.co/Qwen/Qwen2-Audio-7B-Instruct">πŸ€—</a>&nbsp |
117
  &nbsp<a href="https://github.com/QwenLM/Qwen2-Audio">Github</a></center>""")
118
+ chatbot = gr.Chatbot(label='Qwen2-Audio-7B-Instruct', height=750)
119
+
120
+ with gr.Row():
121
+ text_input = gr.Textbox(
122
+ show_label=False,
123
+ placeholder="Type your message here...",
124
+ container=False
125
+ )
126
+ audio_input = gr.Audio(
127
+ sources=["microphone", "upload"],
128
+ type="filepath"
129
+ )
130
 
131
  with gr.Row():
132
+ submit_btn = gr.Button("πŸš€ Submit (发送)")
133
+ empty_btn = gr.Button("🧹 Clear History (ζΈ…ι™€εŽ†ε²)")
134
  regen_btn = gr.Button("πŸ€”οΈ Regenerate (重试)")
135
 
136
+ task_history = gr.State([])
137
+
138
+ # Update event handlers for new input components
139
+ def process_input(text, audio, chatbot, history):
140
+ content = []
141
+ if audio is not None:
142
+ content.append({'type': 'audio', 'audio_url': audio})
143
+ if text:
144
+ content.append({'type': 'text', 'text': text})
145
+
146
+ history.append({"role": "user", "content": content})
147
+ chatbot.append([
148
+ {"text": text, "audio": audio},
149
+ None
150
+ ])
151
+ return "", None, chatbot, history
152
+
153
+ submit_btn.click(
154
+ fn=process_input,
155
+ inputs=[text_input, audio_input, chatbot, task_history],
156
+ outputs=[text_input, audio_input, chatbot, task_history]
157
+ ).then(
158
+ predict,
159
+ [chatbot, task_history],
160
+ [chatbot, task_history],
161
+ show_progress=True
162
  )
163
+
164
+ empty_btn.click(reset_state, outputs=[chatbot, task_history], show_progress=True)
165
  regen_btn.click(regenerate, [chatbot, task_history], [chatbot, task_history], show_progress=True)
166
 
167
  demo.queue().launch(