import gradio as gr from transformers import pipeline trans = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish") classificador = 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 classificador(text)[0]["label"] demo = gr.Blocks() with demo: gr.Markdown("Second demo with Blocks") with gr.Tabs(): with gr.TabItem("Transcribe audio"): with gr.Row(): audio = gr.Audio(source="microphone", type = "filepath") transcription = gr.Textbox() b1 = gr.Button("Transcribe Audio") #b1.click(fn=) with gr.TabItem("Sentiment Analysis"): with gr.Row(): text = gr.Textbox() label = gr.Label() b2 = gr.Button('Classify') b1.click(audio_a_texto, inputs = audio, outputs = transcription) b2.click(texto_a_sentimiento, inputs = text, outputs = label) demo.launch()