kenkina commited on
Commit
262febc
1 Parent(s): cd1e9e4

feat: sentiment analysis and blocks

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -1,15 +1,35 @@
1
- from transformers import pipeline
2
  import gradio as gr
 
3
 
 
 
4
 
5
- modelo = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
6
-
7
- def transcribe(audio):
8
- text = modelo(audio)["text"]
9
  return text
10
 
11
- gr.Interface(
12
- fn = transcribe,
13
- inputs = [ gr.Audio(source="microphone", type="filepath") ],
14
- outputs = ["textbox"]
15
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ trans = pipeline("automatic-speech-recognition", "facebook/wav2vec2-large-xlsr-53-spanish")
5
+ clasificador = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")
6
 
7
+ def audio_a_texto(audio):
8
+ text = trans(audio)["text"]
 
 
9
  return text
10
 
11
+ def texto_a_sentimiento(text):
12
+ return clasificador(text)[0]["label"]
13
+
14
+ demo = gr.Blocks()
15
+
16
+ with demo:
17
+ gr.Markdown("Demo")
18
+ audio = gr.Audio(source = "microphone", type = "filepath")
19
+ texto = gr.Textbox()
20
+ b1 = gr.Button("Transcribe!")
21
+ b1.click(
22
+ fn = audio_a_texto,
23
+ inputs = audio,
24
+ outputs = texto
25
+ )
26
+
27
+ label = gr.Label()
28
+ b2 = gr.Button("Clasify!")
29
+ b2.click(
30
+ fn = texto_a_sentimiento,
31
+ inputs = texto,
32
+ outputs = label
33
+ )
34
+
35
+ demo.launch()