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