Spaces:
Runtime error
Runtime error
Setting the App
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import Gradio Library
|
2 |
+
import gradio as gr
|
3 |
+
# Getting Pipelines
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
# Setting the pipeline model for Speech Recognition
|
7 |
+
trans = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
|
8 |
+
# Pipeline's Classifier for Text Classification
|
9 |
+
classifier = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")
|
10 |
+
|
11 |
+
|
12 |
+
# Function's definition
|
13 |
+
|
14 |
+
def audio_to_text(audio):
|
15 |
+
text = trans(audio)["text"]
|
16 |
+
return text
|
17 |
+
|
18 |
+
def text_to_sentiment(text):
|
19 |
+
return classifier(text)[0]["label"]
|
20 |
+
|
21 |
+
|
22 |
+
# Setting Block
|
23 |
+
demo = gr.Blocks()
|
24 |
+
|
25 |
+
with demo:
|
26 |
+
# Documnetation
|
27 |
+
gr.Markdown("Spanish Sentiment-Demo")
|
28 |
+
# Receiving Audio
|
29 |
+
audio = gr.Audio(source="microphone", type="filepath")
|
30 |
+
# Text Box
|
31 |
+
text = gr.Textbox()
|
32 |
+
# Button's Set-up Box
|
33 |
+
b1 = gr.Button("Please, transcribe..!: ")
|
34 |
+
# Procedure
|
35 |
+
b1.click(audio_to_text, inputs=audio, outputs=text)
|
36 |
+
|
37 |
+
# Labels
|
38 |
+
label = gr.Label()
|
39 |
+
# Sentiment classifier
|
40 |
+
b2 = gr.Button("Please! Classiffy the sentiment: ")
|
41 |
+
# Invoke text to sentiment as text and return a label
|
42 |
+
b2.click(text_to_sentiment, inputs=text, outputs=label)
|
43 |
+
|
44 |
+
demo.launch()
|