malihoseini commited on
Commit
3a6e26f
·
verified ·
1 Parent(s): 97f592c

Update app.py

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