RaymundoSGlz commited on
Commit
a37eb6b
1 Parent(s): 3cf9ba4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Definimos el modelo
5
+ trans = pipeline(
6
+ "automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish"
7
+ )
8
+ clasificador = pipeline(
9
+ "text-classification", model="pysentimiento/robertuito-sentiment-analysis"
10
+ )
11
+
12
+
13
+ def audio_a_texto(audio):
14
+ texto = trans(audio)["text"]
15
+ return texto
16
+
17
+
18
+ def texto_a_sentimiento(texto):
19
+ sentimiento = clasificador(texto)[0]["label"]
20
+ return sentimiento
21
+
22
+
23
+ demo = gr.Blocks()
24
+
25
+ with demo:
26
+ gr.Markdown("Transcripción de audio y clasificación de sentimiento") # Título
27
+ with gr.Tabs(): # Tabs para dividir la interfaz según la tarea
28
+ with gr.TabItem(
29
+ "Transcripción de audio en Español"
30
+ ): # Tab para transcribir audio
31
+ with gr.Row(): # Row para mostrar el input y output en la misma línea
32
+ audio = gr.Audio(source="microphone", type="filepath")
33
+ transcription = gr.Textbox() # Textbox para mostrar la transcripción
34
+ b1 = gr.Button("Transcribir") # Botón para transcribir el audio
35
+ with gr.TabItem(
36
+ "Análisis de sentimiento en Español"
37
+ ): # Tab para clasificar sentimiento
38
+ with gr.Row(): # Row para mostrar el input y output en la misma línea
39
+ texto = gr.Textbox() # Textbox para mostrar el texto
40
+ sentiment = gr.Label() # Label para mostrar el sentimiento
41
+ b2 = gr.Button("Clasificar") # Botón para clasificar el sentimiento
42
+ b1.click(
43
+ audio_a_texto, inputs=audio, outputs=transcription
44
+ ) # Al hacer click, se ejecuta la función audio_a_texto
45
+ b2.click(
46
+ texto_a_sentimiento, inputs=texto, outputs=sentiment
47
+ ) # Al hacer click, se ejecuta la función texto_a_sentimiento
48
+
49
+ demo.launch()