Docty commited on
Commit
55658f9
·
verified ·
1 Parent(s): 015b4fa

Create custom.py

Browse files
Files changed (1) hide show
  1. custom.py +23 -0
custom.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+
3
+ inception_net = tf.keras.applications.MobileNetV2()
4
+
5
+ import requests
6
+
7
+ # Download human-readable labels for ImageNet.
8
+ response = requests.get("https://git.io/JJkYN")
9
+ labels = response.text.split("\n")
10
+
11
+ def classify_image(inp):
12
+ inp = inp.reshape((-1, 224, 224, 3))
13
+ inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
14
+ prediction = inception_net.predict(inp).flatten()
15
+ confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
16
+ return confidences
17
+
18
+ import gradio as gr
19
+
20
+ gr.Interface(fn=classify_image,
21
+ inputs=gr.Image(width=224, height=224),
22
+ outputs=gr.Label(num_top_classes=3),
23
+ examples=["banana.jpg", "car.jpg"]).launch()