Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,21 +4,20 @@ import gradio as gr
|
|
4 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
5 |
classifier = pipeline("text-classification", "michellejieli/emotion_text_classifier")
|
6 |
|
7 |
-
def transcribe(
|
8 |
-
text =
|
9 |
-
|
|
|
10 |
|
11 |
def speech_to_text(speech):
|
12 |
text = asr(speech)["text"]
|
13 |
return text
|
14 |
|
15 |
-
|
16 |
def text_to_sentiment(text):
|
17 |
return classifier(text)[0]["label"]
|
18 |
|
19 |
|
20 |
demo = gr.Blocks()
|
21 |
-
|
22 |
with demo:
|
23 |
|
24 |
microphone = gr.Audio(source="microphone", type="filepath")
|
@@ -26,11 +25,11 @@ with demo:
|
|
26 |
text = gr.Textbox()
|
27 |
label = gr.Label()
|
28 |
|
29 |
-
b0 = gr.Button("
|
30 |
b1 = gr.Button("Recognize Speech")
|
31 |
b2 = gr.Button("Classify Sentiment")
|
32 |
|
33 |
-
b0.click(transcribe, inputs=microphone, outputs=text)
|
34 |
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
35 |
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
36 |
|
|
|
4 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
5 |
classifier = pipeline("text-classification", "michellejieli/emotion_text_classifier")
|
6 |
|
7 |
+
def transcribe(speech, state=""):
|
8 |
+
text = asr(speech)["text"]
|
9 |
+
state += text + " "
|
10 |
+
return text, state
|
11 |
|
12 |
def speech_to_text(speech):
|
13 |
text = asr(speech)["text"]
|
14 |
return text
|
15 |
|
|
|
16 |
def text_to_sentiment(text):
|
17 |
return classifier(text)[0]["label"]
|
18 |
|
19 |
|
20 |
demo = gr.Blocks()
|
|
|
21 |
with demo:
|
22 |
|
23 |
microphone = gr.Audio(source="microphone", type="filepath")
|
|
|
25 |
text = gr.Textbox()
|
26 |
label = gr.Label()
|
27 |
|
28 |
+
b0 = gr.Button("Speech From Microphone")
|
29 |
b1 = gr.Button("Recognize Speech")
|
30 |
b2 = gr.Button("Classify Sentiment")
|
31 |
|
32 |
+
b0.click(transcribe, inputs=microphone, outputs=text, "state", live=True)
|
33 |
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
34 |
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
35 |
|