JLS commited on
Commit
e532a54
1 Parent(s): 72b8adb

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
+ #jonatasgrosman/wav2vec2-large-xlsr-53-spanish
6
+ asr = pipeline("automatic-speech-recognition", "jonatasgrosman/wav2vec2-large-xlsr-53-spanish")
7
+ classifier = pipeline("text-classification", "finiteautomata/beto-sentiment-analysis")
8
+
9
+
10
+ def speech_to_text(speech):
11
+ text = asr(speech)["text"]
12
+ return text
13
+
14
+
15
+ def text_to_sentiment(text):
16
+ return classifier(text)[0]["label"]
17
+
18
+
19
+ demo = gr.Blocks()
20
+
21
+ with demo:
22
+ audio_file = gr.Audio(type="filepath")
23
+ text = gr.Textbox()
24
+ label = gr.Label()
25
+
26
+ b1 = gr.Button("Recognize Speech")
27
+ b2 = gr.Button("Classify Sentiment")
28
+
29
+ b1.click(speech_to_text, inputs=audio_file, outputs=text)
30
+ b2.click(text_to_sentiment, inputs=text, outputs=label)
31
+
32
+ demo.launch(inline=false)