olive100 commited on
Commit
9a06530
1 Parent(s): 8508a18

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ import gradio as gr
4
+
5
+ asr = pipeline("automatic-speech-recognition", "jonatasgrosman/wav2vec2-large-xlsr-53-chinese-zh-cn")
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
+ if __name__ == "__main__":
32
+ demo.launch()