File size: 1,161 Bytes
123e01b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import Gradio Library
import gradio as gr
# Getting Pipelines
from transformers import pipeline

# Setting the pipeline model for Speech Recognition
trans = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
# Pipeline's Classifier for Text Classification
classifier = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")


# Function's definition

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

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


# Setting Block
demo = gr.Blocks()

with demo:
  # Documnetation
  gr.Markdown("Spanish Sentiment-Demo")
  # Receiving Audio
  audio = gr.Audio(source="microphone", type="filepath")
  # Text Box
  text = gr.Textbox()
  # Button's Set-up Box
  b1 = gr.Button("Please, transcribe..!: ")
  # Procedure
  b1.click(audio_to_text, inputs=audio, outputs=text)
  
  # Labels
  label = gr.Label()
  # Sentiment classifier
  b2 = gr.Button("Please! Classiffy the sentiment: ")
  # Invoke text to sentiment as text and return a label
  b2.click(text_to_sentiment, inputs=text, outputs=label)

demo.launch()