File size: 1,012 Bytes
27f2be3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
classifier = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")

def audio_to_text(audio):
  text = trans(audio)["text"]
  return text

def text_to_sentiment(text):
  return classifier(text)[0]["label"]

demo = gr.Blocks()

with demo:
  gr.Markdown("This is the second demo with Blocks")
  with gr.Tabs():
    with gr.TabItem("Transcribe audio in Spanish"):
      with gr.Row():
        audio = gr.Audio(source="microphone", type="filepath")
        transcription = gr.Textbox()
      b1 = gr.Button("Transcribe")
    
    with gr.TabItem("Sentiment Analysis in Spanish"):
      with gr.Row():
        texto = gr.Textbox()
        label = gr.Label()
      b2 = gr.Button("Sentiment")

    b1.click(audio_to_text, inputs=audio, outputs=transcription)
    b2.click(text_to_sentiment, inputs=texto, outputs=label)

demo.launch()