Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
inception_net = tf.keras.applications.MobileNetV2()
|
3 |
+
|
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 |
+
|
19 |
+
import gradio as gr
|
20 |
+
|
21 |
+
gr.Interface(fn=classify_image,
|
22 |
+
inputs=gr.Image(shape=(224, 224)),
|
23 |
+
outputs=gr.Label(num_top_classes=3)).launch()
|