joacorf33's picture
Setting the App
123e01b
# 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()