alexrods commited on
Commit
07c3b8d
·
1 Parent(s): 010eb65

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 classify_imagen(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 audio2text(audio):
16
+ text = trans(audio)["text"]
17
+ return text
18
+
19
+
20
+ def text2sentiment(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
+ demo = gr.Blocks()
28
+
29
+ with demo:
30
+ gr.Markdown("# Demo con Blocks")
31
+ with gr.Tabs():
32
+
33
+ with gr.TabItem("Transcribe Audio en español"):
34
+ with gr.Row():
35
+ audio = gr.Audio(source='microphone', type='filepath')
36
+ transcript = gr.Textbox()
37
+ b1 = gr.Button("Transcribe")
38
+
39
+ with gr.TabItem("Analisis de sentimiento"):
40
+ with gr.Row():
41
+ texto = gr.Textbox()
42
+ label = gr.Label()
43
+ b2 = gr.Button("Sentimiento")
44
+
45
+ b1.click(audio2text, inputs=audio, outputs=transcript)
46
+ b2.click(text2sentiment, inputs=texto, outputs=label)
47
+
48
+ with gr.TabItem("Clasificador de imagenes"):
49
+ with gr.Row():
50
+ image = gr.Image(shape=(224, 224))
51
+ label= gr.Label(num_top_classes=3)
52
+ bimage= gr.Button("Clasifica")
53
+
54
+ bimage.click(classify_imagen, inputs=image, outputs=label)
55
+
56
+
57
+ if __name__ == '__main__':
58
+
59
+ demo.launch()