Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
| 6 |
+
classifier = pipeline("text-classification")
|
| 7 |
+
|
| 8 |
+
def speech_to_text(speech):
|
| 9 |
+
text = asr(speech)["text"]
|
| 10 |
+
return text
|
| 11 |
+
|
| 12 |
+
def text_to_sentiment(text):
|
| 13 |
+
return classifier(text)[0]["label"]
|
| 14 |
+
|
| 15 |
+
demo = gr.Blocks()
|
| 16 |
+
|
| 17 |
+
with demo:
|
| 18 |
+
audio_file = gr.Audio(type="filepath")
|
| 19 |
+
text = gr.Textbox()
|
| 20 |
+
label = gr.Label()
|
| 21 |
+
|
| 22 |
+
b1 = gr.Button("Recognize Speech")
|
| 23 |
+
b2 = gr.Button("Classify Sentiment")
|
| 24 |
+
|
| 25 |
+
b1.click(speech_to_text, inputs=audio_file, outputs=text)
|
| 26 |
+
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
| 27 |
+
|
| 28 |
+
demo.launch()
|