KeniBrandonGM commited on
Commit
36ff57a
·
1 Parent(s): d8df2e1

Creacion del demo con Gradio blocks y TabItem

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+
3
+ inception_net = tf.keras.applications.M
4
+
5
+ import requests
6
+
7
+ respuesta = requests.get("https://git.io/JJkYN")
8
+ etiquetas = respuesta.text.split("\n")
9
+ # Obteniendo las labels de "https://git.io/JJkYN"
10
+
11
+ def clasifica_imagen(inp):
12
+ inp = inp.reshape((-1,224,224,3))
13
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
14
+ prediction = inception_net.predict(inp).flatten()
15
+ confidences = {etiquetas[i]: float(prediction[i]) for i in range(1000)}
16
+ return confidences
17
+
18
+ import gradio as gr
19
+ from transformers import pipeline
20
+
21
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
22
+ clasificador = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
23
+
24
+ def audio_a_text(audio):
25
+ text = trans(audio)["text"]
26
+ return text
27
+
28
+ def texto_a_sentimiento(text):
29
+ return clasificador(text)[0]["label"]
30
+
31
+
32
+ demo = gr.Blocks()
33
+
34
+ with demo:
35
+ gr.Markdown("Este es el segundo demo con Blocks")
36
+ with gr.Tabs():
37
+ with gr.TabItem("Transcribe audio en español"):
38
+ with gr.Row():
39
+ audio = gr.Audio(source="microphone", type="filepath")
40
+ transcripcion = gr.Textbox()
41
+ b1 = gr.Button("Transcribe porfa")
42
+
43
+ with gr.TabItem("Análisis de sentimiento en español"):
44
+ with gr.Row():
45
+ texto = gr.Textbox()
46
+ label = gr.Label()
47
+ b2 = gr.Button("sentimiento porfa")
48
+
49
+ with gr.TabItem("Clasificacion de imagenes"):
50
+ with gr.Row():
51
+ imagen = gr.Image(shape=(224,224))
52
+ label1 = gr.Label(num_top_classes=3)
53
+ b3 = gr.Button("clasifica")
54
+
55
+
56
+ b1.click(audio_a_text, inputs = audio, outputs = transcripcion)
57
+ b2.click(texto_a_sentimiento, inputs = texto, outputs = label)
58
+ b3.click(clasifica_imagen, inputs = imagen, outputs=label1)
59
+
60
+
61
+ demo.launch()