Spaces:
Runtime error
Runtime error
Commit
路
a37eb6b
1
Parent(s):
3cf9ba4
Upload app.py
Browse files
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()
|