Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from transformers import pipeline
|
4 |
+
import tensorflow as tf
|
5 |
+
|
6 |
+
inception_net = tf.keras.applications.MobileNetV2()
|
7 |
+
|
8 |
+
# Obteniendo las labels de "https://git.io/JJkYN"
|
9 |
+
respuesta = requests.get("https://raw.githubusercontent.com/gradio-app/mobilenet-example/master/labels.txt")
|
10 |
+
etiquetas =respuesta.text.split("\n")
|
11 |
+
|
12 |
+
def clasifica_imagen(inp):
|
13 |
+
inp = inp.reshape((-1,224,224,3))
|
14 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
15 |
+
prediction = inception_net.predict(inp).flatten()
|
16 |
+
confidences ={etiquetas[i]: float(prediction[i]) for i in range(1000)}
|
17 |
+
return confidences
|
18 |
+
|
19 |
+
def audio_a_text(audio):
|
20 |
+
text = trans(audio)["text"]
|
21 |
+
return text
|
22 |
+
|
23 |
+
def texto_a_sentimiento(text):
|
24 |
+
return clasificador(text)[0]["label"]
|
25 |
+
|
26 |
+
demo = gr.Blocks()
|
27 |
+
|
28 |
+
with demo:
|
29 |
+
gr.Markdown("Este es el segundo demo con Blocks")
|
30 |
+
with gr.Tabs():
|
31 |
+
with gr.TabItem("Transcribe audio en español"):
|
32 |
+
with gr.Row():
|
33 |
+
audio = gr.Audio(source="microphone", type="filepath")
|
34 |
+
transcripcion = gr.Textbox()
|
35 |
+
b1 = gr.Button("Transcribe porfa")
|
36 |
+
|
37 |
+
with gr.TabItem("Análisis de sentimiento en español"):
|
38 |
+
with gr.Row():
|
39 |
+
texto = gr.Textbox()
|
40 |
+
label = gr.Label()
|
41 |
+
b2 = gr.Button("Sentimiento porfa")
|
42 |
+
|
43 |
+
with gr.TabItem("clasificación de imágenes"):
|
44 |
+
with gr.Row():
|
45 |
+
image = gr.Image(shape=(224,224))
|
46 |
+
label = gr.Label(num_top_classes=3)
|
47 |
+
b3 = gr.Button("clasificar")
|
48 |
+
|
49 |
+
b1.click(audio_a_text, inputs = audio, outputs=transcripcion)
|
50 |
+
b2.click(texto_a_sentimiento, inputs=texto, outputs=label)
|
51 |
+
b3.click(clasifica_imagen, inputs=image, outputs=label)
|
52 |
+
|
53 |
+
demo.launch()
|