|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
transcription = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish") |
|
clasificator = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis") |
|
|
|
def speech_to_text(audio): |
|
text = transcription(audio)["text"] |
|
return text |
|
|
|
def text_to_sentiment(text): |
|
return clasificator(text)[0]["label"] |
|
|
|
|
|
demo = gr.Blocks() |
|
|
|
with demo: |
|
gr.Markdown("Obtener texto de un audio y analizar el sentimiento") |
|
with gr.Tabs(): |
|
with gr.TabItem("Transcribir audio en español"): |
|
with gr.Row(): |
|
audio = gr.Audio(type="filepath") |
|
transcripcion = gr.Textbox() |
|
|
|
with gr.Row(): |
|
gr.Markdown("") |
|
|
|
b1 = gr.Button("Generar texto") |
|
|
|
with gr.TabItem("Análisis de sentimiento en español"): |
|
with gr.Row(): |
|
texto = gr.Textbox() |
|
label = gr.Label() |
|
b2 = gr.Button("Analizar sentimiento") |
|
|
|
b1.click(speech_to_text, inputs = audio, outputs = transcripcion) |
|
b2.click(text_to_sentiment, inputs=texto, outputs=label) |
|
|
|
demo.launch(share=True) |
|
|
|
|