Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,26 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
arr = np.expand_dims(im, axis=0)
|
| 17 |
-
arr = tf.keras.applications.mobilenet.preprocess_input(arr)
|
| 18 |
-
prediction = mobile_net.predict(arr).flatten()
|
| 19 |
return {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
["images/lion.jpg"]
|
| 30 |
-
])
|
| 31 |
-
|
| 32 |
-
if __name__ == "__main__":
|
| 33 |
-
iface.launch(share=True)
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import tensorflow as tf
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
+
|
| 6 |
+
inception_net = tf.keras.applications.MobileNetV2() # load the model
|
| 7 |
+
|
| 8 |
+
# Download human-readable labels for ImageNet.
|
| 9 |
+
response = requests.get("https://git.io/JJkYN")
|
| 10 |
+
labels = response.text.split("\n")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def classify_image(inp):
|
| 14 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
| 15 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
| 16 |
+
prediction = inception_net.predict(inp).flatten()
|
|
|
|
|
|
|
|
|
|
| 17 |
return {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 18 |
|
| 19 |
+
|
| 20 |
+
image = gr.Image(shape=(224, 224))
|
| 21 |
+
label = gr.Label(num_top_classes=3)
|
| 22 |
+
|
| 23 |
+
title = "Gradio Image Classifiction + Interpretation Example"
|
| 24 |
+
gr.Interface(
|
| 25 |
+
fn=classify_image, inputs=image, outputs=label, interpretation="default", title=title
|
| 26 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|