Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,22 @@
|
|
1 |
-
import torch
|
2 |
-
|
3 |
-
model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).eval()
|
4 |
-
|
5 |
import requests
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
# Download human-readable labels for ImageNet.
|
10 |
-
response = requests.get("https://git.io/JJkYN")
|
11 |
-
labels = response.text.split("\n")
|
12 |
|
13 |
-
def
|
14 |
-
inp =
|
15 |
-
inp =
|
16 |
-
|
17 |
-
|
18 |
-
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
19 |
return confidences
|
|
|
20 |
|
21 |
import gradio as gr
|
22 |
|
23 |
gr.Interface(fn=predict,
|
24 |
-
inputs=
|
25 |
outputs=gr.outputs.Label(num_top_classes=3),
|
26 |
-
examples=["
|
27 |
theme="default",
|
28 |
css=".footer{display:none !important}").launch()
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import tensorflow as tf
|
3 |
+
|
4 |
+
inception_net = tf.keras.applications.MobileNetV2()
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
+
def classify_image(inp):
|
8 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
9 |
+
inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
|
10 |
+
prediction = inception_net.predict(inp).flatten()
|
11 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
|
|
|
12 |
return confidences
|
13 |
+
|
14 |
|
15 |
import gradio as gr
|
16 |
|
17 |
gr.Interface(fn=predict,
|
18 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
19 |
outputs=gr.outputs.Label(num_top_classes=3),
|
20 |
+
examples=["banana.jpg", "car.jpg"]).launch(),
|
21 |
theme="default",
|
22 |
css=".footer{display:none !important}").launch()
|