rriverar75 commited on
Commit
5fba195
1 Parent(s): 656ecf4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
15
+ def audio2text(audio):
16
+ text = trans(audio)["text"]
17
+ return text
18
+
19
+ classificator = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
20
+ def text2sentiment(text):
21
+ return classificator(text)[0]['label']
22
+
23
+
24
+ demo = gr.Blocks()
25
+
26
+ with demo:
27
+ gr.Markdown("Este es el segundo demo con Blocks hecho por Rafa")
28
+ with gr.Tabs():
29
+
30
+ with gr.TabItem("Transcribe Audio en español"):
31
+ with gr.Row():
32
+ audio = gr.Audio(source='microphone', type='filepath')
33
+ transcript = gr.Textbox()
34
+ b1 = gr.Button("Transcribe")
35
+
36
+ with gr.TabItem("Analisis de sentimientos"):
37
+ with gr.Row():
38
+ texto = gr.Textbox()
39
+ label = gr.Label()
40
+ b2 = gr.Button("Sentimientos")
41
+
42
+ b1.click(audio2text, inputs=audio, outputs=transcript)
43
+ b2.click(text2sentiment, inputs=texto, outputs=label)
44
+
45
+ with gr.TabItem("Clasificador de imagenes"):
46
+ with gr.Row():
47
+ image = gr.Image(shape=(224, 224))
48
+ label= gr.Label(num_top_classes=3)
49
+ bimage= gr.Button("Clasificar")
50
+
51
+ bimage.click(classify_imagen, inputs=image, outputs=label)
52
+
53
+ demo.launch()