Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
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")
|
@@ -74,10 +76,26 @@ def predict(input_img):
|
|
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=
|
79 |
inputs=gr.Image(label="Upload an Image", type="pil"),
|
80 |
-
outputs=gr.
|
81 |
title="Predict the Location of this Image"
|
82 |
)
|
83 |
|
|
|
1 |
import os
|
2 |
from huggingface_hub import Repository
|
3 |
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
|
7 |
# Retrieve the token from the environment variables
|
8 |
token = os.environ.get("token")
|
|
|
76 |
results = {top_10_predictions[i]: float(top_10_probabilities[i]) for i in range(10)}
|
77 |
return results
|
78 |
|
79 |
+
def create_bar_plot(predictions):
|
80 |
+
data = pd.DataFrame(list(predictions.items()), columns=["Location", "Probability"])
|
81 |
+
return gr.BarPlot(
|
82 |
+
data,
|
83 |
+
x="Location",
|
84 |
+
y="Probability",
|
85 |
+
title="Top 10 Predictions with Probabilities",
|
86 |
+
tooltip=["Location", "Probability"],
|
87 |
+
y_lim=[0, 1]
|
88 |
+
)
|
89 |
+
|
90 |
+
def predict_and_plot(input_img):
|
91 |
+
predictions = predict(input_img)
|
92 |
+
return create_bar_plot(predictions)
|
93 |
+
|
94 |
+
|
95 |
gradio_app = gr.Interface(
|
96 |
+
fn=predict_and_plot,
|
97 |
inputs=gr.Image(label="Upload an Image", type="pil"),
|
98 |
+
outputs=gr.BarPlot(),
|
99 |
title="Predict the Location of this Image"
|
100 |
)
|
101 |
|