Spaces:
Build error
Build error
davidmasip
commited on
Commit
·
8c508e1
1
Parent(s):
9a1ed21
inception
Browse files
app.py
CHANGED
@@ -1,8 +1,23 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
def greet(name):
|
5 |
-
return "Hello " + name + "!!"
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import tensorflow as tf
|
3 |
+
|
4 |
+
inception_net = tf.keras.applications.MobileNetV2()
|
5 |
+
|
6 |
+
# Download human-readable labels for ImageNet.
|
7 |
+
response = requests.get("https://git.io/JJkYN")
|
8 |
+
labels = response.text.split("\n")
|
9 |
|
10 |
+
def classify_image(inp):
|
11 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
12 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
13 |
+
prediction = inception_net.predict(inp).flatten()
|
14 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
15 |
+
return confidences
|
16 |
|
|
|
|
|
17 |
|
18 |
+
import gradio as gr
|
19 |
+
|
20 |
+
gr.Interface(fn=classify_image,
|
21 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
22 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
23 |
+
examples=["banana.jpg", "car.jpg"]).launch()
|