Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
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
|
10 |
+
|
11 |
+
|
12 |
+
def text_to_sentiment(text):
|
13 |
+
return classifier(text)[0]["label"]
|
14 |
+
|
15 |
+
|
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(live=True)
|