Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
from huggingface_hub import Repository
|
|
|
3 |
|
4 |
# Retrieve the token from the environment variables
|
5 |
token = os.environ.get("token")
|
@@ -65,15 +66,20 @@ def predict(input_img):
|
|
65 |
with torch.inference_mode():
|
66 |
img = cmp(input_img).unsqueeze(0)
|
67 |
res = modelm(img.to(device))
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
gradio_app = gr.Interface(
|
72 |
fn=predict,
|
73 |
inputs=gr.Image(label="Upload an Image", type="pil"),
|
74 |
-
outputs=gr.
|
75 |
title="Predict the Location of this Image"
|
76 |
)
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
-
gradio_app.launch()
|
|
|
1 |
import os
|
2 |
from huggingface_hub import Repository
|
3 |
+
import numpy as np
|
4 |
|
5 |
# Retrieve the token from the environment variables
|
6 |
token = os.environ.get("token")
|
|
|
66 |
with torch.inference_mode():
|
67 |
img = cmp(input_img).unsqueeze(0)
|
68 |
res = modelm(img.to(device))
|
69 |
+
probabilities = torch.softmax(res, dim=1).cpu().numpy().flatten()
|
70 |
+
top_10_indices = np.argsort(probabilities)[-10:][::-1]
|
71 |
+
top_10_probabilities = probabilities[top_10_indices]
|
72 |
+
top_10_predictions = le.inverse_transform(top_10_indices)
|
73 |
+
|
74 |
+
results = {top_10_predictions[i]: float(top_10_probabilities[i]) for i in range(10)}
|
75 |
+
return results
|
76 |
|
77 |
gradio_app = gr.Interface(
|
78 |
fn=predict,
|
79 |
inputs=gr.Image(label="Upload an Image", type="pil"),
|
80 |
+
outputs=gr.JSON(label="Top 10 Predictions with Probabilities"),
|
81 |
title="Predict the Location of this Image"
|
82 |
)
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
+
gradio_app.launch()
|