Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ 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 speech_to_text(speech):
|
| 8 |
text = asr(speech)["text"]
|
| 9 |
return text
|
|
@@ -16,20 +20,24 @@ def text_to_sentiment(text):
|
|
| 16 |
demo = gr.Blocks()
|
| 17 |
|
| 18 |
with demo:
|
| 19 |
-
|
|
|
|
| 20 |
audio_file = gr.Audio(type="filepath")
|
| 21 |
text = gr.Textbox()
|
| 22 |
label = gr.Label()
|
| 23 |
|
|
|
|
| 24 |
b1 = gr.Button("Recognize Speech")
|
| 25 |
b2 = gr.Button("Classify Sentiment")
|
| 26 |
|
|
|
|
| 27 |
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
| 28 |
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
| 29 |
|
| 30 |
gr.Markdown("""
|
| 31 |
-
ASR Model: https://huggingface.co/facebook/wav2vec2-base-960h
|
| 32 |
-
Sentiment: https://huggingface.co/michellejieli/emotion_text_classifier
|
|
|
|
| 33 |
""")
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
| 4 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
| 5 |
classifier = pipeline("text-classification", "michellejieli/emotion_text_classifier")
|
| 6 |
|
| 7 |
+
def transcribe(audio):
|
| 8 |
+
text = p(audio)["text"]
|
| 9 |
+
return text
|
| 10 |
+
|
| 11 |
def speech_to_text(speech):
|
| 12 |
text = asr(speech)["text"]
|
| 13 |
return text
|
|
|
|
| 20 |
demo = gr.Blocks()
|
| 21 |
|
| 22 |
with demo:
|
| 23 |
+
|
| 24 |
+
microphone = gr.Audio(source="microphone", type="filepath")
|
| 25 |
audio_file = gr.Audio(type="filepath")
|
| 26 |
text = gr.Textbox()
|
| 27 |
label = gr.Label()
|
| 28 |
|
| 29 |
+
b0 = gr.Button("Classify Sentiment")
|
| 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 |
|
| 37 |
gr.Markdown("""
|
| 38 |
+
1. ASR Model: https://huggingface.co/facebook/wav2vec2-base-960h
|
| 39 |
+
2. Sentiment: https://huggingface.co/michellejieli/emotion_text_classifier
|
| 40 |
+
3. ASR Lesson: https://gradio.app/real-time-speech-recognition/
|
| 41 |
""")
|
| 42 |
|
| 43 |
demo.launch()
|