dawood HF staff commited on
Commit
c899d10
1 Parent(s): 988f6f1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ def speech_to_text(speech):
10
+ text = asr(speech)["text"]
11
+ return text
12
+
13
+
14
+ def text_to_sentiment(text):
15
+ return classifier(text)[0]["label"]
16
+
17
+
18
+ demo = gr.Blocks()
19
+
20
+ with demo:
21
+ audio_file = gr.Audio(type="filepath")
22
+ text = gr.Textbox()
23
+ label = gr.Label()
24
+
25
+ b1 = gr.Button("Recognize Speech")
26
+ b2 = gr.Button("Classify Sentiment")
27
+
28
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
29
+ b2.click(text_to_sentiment, inputs=text, outputs=label)
30
+
31
+ demo.launch()