malihoseini commited on
Commit
e524508
·
verified ·
1 Parent(s): 42657c8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ import json
5
+ from os.path import dirname, realpath, join
6
+ import matplotlib.pyplot as plt
7
+
8
+ current_dir = dirname(realpath(__file__))
9
+ with open(join(current_dir), 'image_labels.json') as labels_file:
10
+ labels=json.load(labels_file)
11
+
12
+ mobile_net = tf.keras.applications.MobileNetV2()
13
+ def image_classifier(img):
14
+ arr = np.expand_dims(img, axis=0)
15
+ arr = tf.keras.applications.mobilenet.preprocess_input(arr)
16
+ prediction = mobile_net.prediction(arr).flatten()
17
+ return {labels[i]:float(prediction[i]) for i in range(1000)}
18
+ iface = gr.Interface(
19
+ image_classifier,
20
+ inputs=gr.Image(height=224, width=224),
21
+ outputs=gr.Label(num_top_classes=3),
22
+ capture_session=True,
23
+ interpretation='default',
24
+ )
25
+ if __name__ == '__main__':
26
+ iface.launch(share=True)