Spaces:
Runtime error
Runtime error
Commit
·
913a67b
1
Parent(s):
45a10df
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
trans = pipeline("automatic-speech-recognition", model = "facebook/wav2vec2-large-xlsr-53-spanish")
|
| 5 |
+
clasificador = pipeline("text-classification", model = "pysentimiento/robertuito-sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def audio_a_texto(audio):
|
| 9 |
+
text = trans(audio)["text"]
|
| 10 |
+
return text
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def texto_a_sentimiento(text):
|
| 14 |
+
return clasificador(text)[0]["label"]
|
| 15 |
+
|
| 16 |
+
demo = gr.Blocks()
|
| 17 |
+
|
| 18 |
+
with demo:
|
| 19 |
+
gr.Markdown("Demo para la clase de Platzi sobre cómo usar los Blocks de Gradio.")
|
| 20 |
+
audio = gr.Audio(source="microphone", type="filepath")
|
| 21 |
+
texto = gr.Textbox()
|
| 22 |
+
label = gr.Label()
|
| 23 |
+
|
| 24 |
+
b1 = gr.Button("Transcribe mi voz porfa")
|
| 25 |
+
b2 = gr.Button("Clasifica el sentimiento de mi texto porfa")
|
| 26 |
+
|
| 27 |
+
b1.click(audio_a_texto, inputs=audio, outputs=texto)
|
| 28 |
+
b2.click(texto_a_sentimiento, inputs=texto, outputs=label)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|