marcela9409 commited on
Commit
1b1c1e7
·
verified ·
1 Parent(s): 38e1d9a

Demo with 3 tabs

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from numpy import asarray
3
+ import gradio as gr
4
+ from transformers import pipeline
5
+
6
+ answer = requests.get("https://git.io/JJkYN")
7
+ labels =answer.text.split("\n")
8
+
9
+ def classify_image(inp):
10
+ inp = asarray(inp.resize((224, 224)))
11
+ inp = inp.reshape((-1,) + inp.shape)
12
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
13
+ prediction = inception_net.predict(inp).flatten()
14
+ confidences = {labels[k]: float(prediction[k]) for k in range(1000)}
15
+ return confidences
16
+
17
+ def audio_to_text(audio):
18
+ text = transcribe(audio)["text"]
19
+ return text
20
+
21
+ def text_to_sentiment(text):
22
+ return classifier(text)[0]["label"]
23
+
24
+
25
+ demo = gr.Blocks()
26
+
27
+ with demo:
28
+ gr.Markdown("Example with Gradio Blocks")
29
+ with gr.Tabs():
30
+ with gr.TabItem("Transcribe audio in Spanish"):
31
+ with gr.Row():
32
+ audio = gr.Audio(sources="microphone", type="filepath")
33
+ transcription = gr.Textbox()
34
+ transcribeButton = gr.Button("Transcribe")
35
+
36
+ with gr.TabItem("Sentiment analysis in English and Spanish"):
37
+ with gr.Row():
38
+ text = gr.Textbox()
39
+ label = gr.Label()
40
+ sentimentButton = gr.Button("Calculate sentiment")
41
+
42
+ with gr.TabItem("Image Classification"):
43
+ with gr.Row():
44
+ image = gr.Image(label="Upload an image here")
45
+ label_image = gr.Label(num_top_classes=3)
46
+ classifyButton = gr.Button("Classify image")
47
+
48
+ transcribeButton.click(audio_to_text, inputs = audio, outputs=transcription)
49
+ sentimentButton.click(text_to_sentiment, inputs=text, outputs=label)
50
+ classifyButton. click(classify_image, inputs=image, outputs=label_image)
51
+
52
+ demo.launch()