LRascon commited on
Commit
b8e69b5
1 Parent(s): ff9d8ac

Creación de app

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from transformers import pipeline
4
+
5
+ inception_net = tf.keras.applications.MobileNetV2()
6
+ def clasificador_imagenes(inp):
7
+ inp = inp.reshape((-1, 224, 224, 3))
8
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
9
+ prediction = inception_net.predict(inp).reshape(1,1000)
10
+ pred_scores = tf.keras.applications.mobilenet_v2.decode_predictions(prediction, top=100)
11
+ confidence = {f'{pred_scores[0][i][1]}': float(pred_scores[0][i][2]) for i in range(100)}
12
+ return confidence
13
+
14
+
15
+ def audio_a_texto(audio):
16
+ text = trans(audio)["text"]
17
+ return text
18
+
19
+
20
+ def texto_a_sentimiento(text):
21
+ return classificator(text)[0]['label']
22
+
23
+
24
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
25
+ classificator = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
26
+
27
+
28
+ demo = gr.Blocks()
29
+
30
+ with demo:
31
+ gr.Markdown("# Demo con Blocks")
32
+ with gr.Tabs():
33
+
34
+ with gr.TabItem("Transcribe Audio en español"):
35
+ with gr.Row():
36
+ audio = gr.Audio(source='microphone', type='filepath')
37
+ transcript = gr.Textbox()
38
+ b1 = gr.Button("Transcribe")
39
+
40
+ with gr.TabItem("Analisis de sentimiento"):
41
+ with gr.Row():
42
+ texto = gr.Textbox()
43
+ label = gr.Label()
44
+ b2 = gr.Button("Sentimiento")
45
+
46
+ b1.click(audio_a_texto, inputs=audio, outputs=transcript)
47
+ b2.click(texto_a_sentimiento, inputs=texto, outputs=label)
48
+
49
+ with gr.TabItem("Clasificador de imagenes"):
50
+ with gr.Row():
51
+ image = gr.Image(shape=(224, 224))
52
+ label= gr.Label(num_top_classes=3)
53
+ bimage= gr.Button("Clasifica")
54
+
55
+ bimage.click(clasificador_imagenes, inputs=image, outputs=label)
56
+
57
+ demo.launch()