espejelomar's picture
Create new file
913a67b
raw
history blame
885 Bytes
import gradio as gr
from transformers import pipeline
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):
text = trans(audio)["text"]
return text
def texto_a_sentimiento(text):
return clasificador(text)[0]["label"]
demo = gr.Blocks()
with demo:
gr.Markdown("Demo para la clase de Platzi sobre cómo usar los Blocks de Gradio.")
audio = gr.Audio(source="microphone", type="filepath")
texto = gr.Textbox()
label = gr.Label()
b1 = gr.Button("Transcribe mi voz porfa")
b2 = gr.Button("Clasifica el sentimiento de mi texto porfa")
b1.click(audio_a_texto, inputs=audio, outputs=texto)
b2.click(texto_a_sentimiento, inputs=texto, outputs=label)
demo.launch()