malihoseini commited on
Commit
d67d257
·
verified ·
1 Parent(s): cdd7380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -1,26 +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)
 
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
+ gr.inputs.Image(height=224, width=224),
21
+ gr.outputs.Label(num_top_classes=3),
22
+ capture_session=True,
23
+ interpretation='default',
24
+ )
25
+ if __name__ == '__main__':
26
  iface.launch(share=True)