Spaces:
Runtime error
Runtime error
Adding TF req
Browse files- app.py +8 -8
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -7,10 +7,10 @@ sys.path.append("/hub")
|
|
| 7 |
import gradio as gr
|
| 8 |
from hub.tensorflow_hub.hf_utils import pull_from_hub
|
| 9 |
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
|
| 16 |
|
|
@@ -23,14 +23,14 @@ def preprocess(image):
|
|
| 23 |
print(image / 255.)
|
| 24 |
return image / 255.
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
def predict_fn(image):
|
| 30 |
image = preprocess(image)
|
| 31 |
prediction = model([image])
|
| 32 |
-
|
| 33 |
-
return
|
| 34 |
|
| 35 |
iface = gr.Interface(fn=predict_fn,
|
| 36 |
inputs=gr.Image(shape=(224, 224)),
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
from hub.tensorflow_hub.hf_utils import pull_from_hub
|
| 9 |
|
| 10 |
+
import requests
|
| 11 |
+
# Download human-readable labels for ImageNet.
|
| 12 |
+
response = requests.get("https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt")
|
| 13 |
+
labels = [x for x in response.text.split("\n") if x != ""]
|
| 14 |
|
| 15 |
model = pull_from_hub(repo_id="Dimitre/mobilenet_v3_small")
|
| 16 |
|
|
|
|
| 23 |
print(image / 255.)
|
| 24 |
return image / 255.
|
| 25 |
|
| 26 |
+
def postprocess(prediction):
|
| 27 |
+
return {labels[i]: prediction[i] for i in range(len(labels))}
|
| 28 |
|
| 29 |
def predict_fn(image):
|
| 30 |
image = preprocess(image)
|
| 31 |
prediction = model([image])
|
| 32 |
+
scores = postprocess(prediction)
|
| 33 |
+
return scores
|
| 34 |
|
| 35 |
iface = gr.Interface(fn=predict_fn,
|
| 36 |
inputs=gr.Image(shape=(224, 224)),
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
GitPython
|
|
|
|
|
|
| 1 |
+
GitPython
|
| 2 |
+
tensorflow
|