Spaces:
Runtime error
Runtime error
Commit
·
7f93957
1
Parent(s):
98b5314
added audio and submit button
Browse files
app.py
CHANGED
@@ -1,27 +1,48 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import random
|
3 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
with gr.Blocks() as demo:
|
6 |
chatbot = gr.Chatbot()
|
7 |
msg = gr.Textbox()
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
22 |
bot, chatbot, chatbot
|
23 |
)
|
24 |
-
|
|
|
|
|
25 |
|
26 |
demo.queue()
|
27 |
-
demo.launch()
|
|
|
|
|
|
|
1 |
import time
|
2 |
+
import random
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
p = pipeline("automatic-speech-recognition")
|
7 |
+
|
8 |
+
def user(user_message, history):
|
9 |
+
return "", history + [[user_message, None]]
|
10 |
+
|
11 |
+
def transcribe(audio, state=""):
|
12 |
+
text = p(audio)["text"]
|
13 |
+
state += text + " "
|
14 |
+
return state, state
|
15 |
+
|
16 |
+
def bot(history):
|
17 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
18 |
+
history[-1][1] = ""
|
19 |
+
for character in bot_message:
|
20 |
+
history[-1][1] += character
|
21 |
+
time.sleep(0.05)
|
22 |
+
yield history
|
23 |
|
24 |
with gr.Blocks() as demo:
|
25 |
chatbot = gr.Chatbot()
|
26 |
msg = gr.Textbox()
|
27 |
+
gr.Interface(
|
28 |
+
fn=transcribe,
|
29 |
+
inputs=[
|
30 |
+
gr.Audio(source="microphone", type="filepath", streaming=True),
|
31 |
+
"state"
|
32 |
+
],
|
33 |
+
outputs=[
|
34 |
+
msg,
|
35 |
+
"state"
|
36 |
+
],
|
37 |
+
live=True)
|
38 |
+
submit = gr.Button("Submit")
|
39 |
|
40 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
41 |
bot, chatbot, chatbot
|
42 |
)
|
43 |
+
submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
44 |
+
bot, chatbot, chatbot
|
45 |
+
)
|
46 |
|
47 |
demo.queue()
|
48 |
+
demo.launch()
|