Spaces:
Runtime error
Runtime error
j
commited on
Commit
Β·
4bbc7e3
1
Parent(s):
12bd81d
changed modelscope widgets to gradio widgets
Browse files- 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>  ο½
|
| 117 |
 <a href="https://github.com/QwenLM/Qwen2-Audio">Github</a></center>""")
|
| 118 |
-
chatbot =
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
with gr.Row():
|
| 129 |
-
|
|
|
|
| 130 |
regen_btn = gr.Button("π€οΈ Regenerate (ιθ―)")
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
)
|
| 137 |
-
|
|
|
|
| 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>  ο½
|
| 117 |
 <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(
|