jeraldflowers commited on
Commit
27f2be3
1 Parent(s): 98dfbce

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
5
+ classifier = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
6
+
7
+ def audio_to_text(audio):
8
+ text = trans(audio)["text"]
9
+ return text
10
+
11
+ def text_to_sentiment(text):
12
+ return classifier(text)[0]["label"]
13
+
14
+ demo = gr.Blocks()
15
+
16
+ with demo:
17
+ gr.Markdown("This is the second demo with Blocks")
18
+ with gr.Tabs():
19
+ with gr.TabItem("Transcribe audio in Spanish"):
20
+ with gr.Row():
21
+ audio = gr.Audio(source="microphone", type="filepath")
22
+ transcription = gr.Textbox()
23
+ b1 = gr.Button("Transcribe")
24
+
25
+ with gr.TabItem("Sentiment Analysis in Spanish"):
26
+ with gr.Row():
27
+ texto = gr.Textbox()
28
+ label = gr.Label()
29
+ b2 = gr.Button("Sentiment")
30
+
31
+ b1.click(audio_to_text, inputs=audio, outputs=transcription)
32
+ b2.click(text_to_sentiment, inputs=texto, outputs=label)
33
+
34
+ demo.launch()