mgutierrez commited on
Commit
bbc92b2
1 Parent(s): a8439dd

First commit for demo

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''Imports'''
2
+ import tensorflow as tf
3
+ import requests
4
+ from transformers import pipeline
5
+ import gradio as gr
6
+
7
+ '''Config inception'''
8
+ inception_net = tf.keras.applications.MobileNetV2()
9
+
10
+ '''Making request and set database'''
11
+ response = requests.get("https://git.io/JJkYN")
12
+ tags = response.text.split("\n")
13
+
14
+ '''Define model and classify pipelines'''
15
+ trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
16
+ classify = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
17
+
18
+ '''Define functions for demo'''
19
+ def classify_image(inp):
20
+ inp = inp.reshape((-1,224,224,3))
21
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
22
+ prediction = inception_net.predict(inp).flatten()
23
+ confidences = {tags[i]: float(prediction[i]) for i in range(1000)}
24
+ return confidences
25
+
26
+ def audio_to_text(audio):
27
+ text = trans(audio)["text"]
28
+ return text
29
+
30
+ def text_to_sentiment(text):
31
+ return classify(text)[0]["label"]
32
+
33
+ '''Define blocks for demo'''
34
+ demo = gr.Blocks()
35
+
36
+ '''Making demo'''
37
+ with demo:
38
+ gr.Markdown("Demo for platzi class")
39
+ audio = gr.Audio(source="microphone", type="filepath")
40
+ text = gr.Textbox()
41
+ button1 = gr.Button("Please transcribe")
42
+ button1.click(audio_to_text, inputs=audio, outputs=text)
43
+
44
+ label = gr.Label()
45
+ button2 = gr.Button("Please classify the sentiment")
46
+ button2.click(text_to_sentiment, inputs=text, outputs=label)
47
+
48
+ demo.launch()