Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ 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")
|
@@ -79,21 +79,26 @@ def predict(input_img):
|
|
79 |
def create_bar_plot(predictions):
|
80 |
data = pd.DataFrame(list(predictions.items()), columns=["Location", "Probability"])
|
81 |
max_prob = data["Probability"].max()
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
def predict_and_plot(input_img):
|
94 |
predictions = predict(input_img)
|
95 |
return create_bar_plot(predictions)
|
96 |
-
|
97 |
|
98 |
gradio_app = gr.Interface(
|
99 |
fn=predict_and_plot,
|
|
|
2 |
from huggingface_hub import Repository
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
|
7 |
# Retrieve the token from the environment variables
|
8 |
token = os.environ.get("token")
|
|
|
79 |
def create_bar_plot(predictions):
|
80 |
data = pd.DataFrame(list(predictions.items()), columns=["Location", "Probability"])
|
81 |
max_prob = data["Probability"].max()
|
82 |
+
|
83 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
84 |
+
ax.barh(data["Location"], data["Probability"], color='skyblue')
|
85 |
+
ax.set_xlabel('Probability', fontsize=14)
|
86 |
+
ax.set_title('Top 10 Predictions with Probabilities', fontsize=16)
|
87 |
+
ax.set_xlim(0, max_prob)
|
88 |
+
ax.tick_params(axis='y', labelsize=12) # Increase font size for y-axis labels
|
89 |
+
ax.invert_yaxis()
|
90 |
+
|
91 |
+
# Save the plot to a BytesIO object
|
92 |
+
buf = io.BytesIO()
|
93 |
+
plt.savefig(buf, format='png')
|
94 |
+
buf.seek(0)
|
95 |
+
|
96 |
+
return buf
|
97 |
|
98 |
def predict_and_plot(input_img):
|
99 |
predictions = predict(input_img)
|
100 |
return create_bar_plot(predictions)
|
101 |
+
|
102 |
|
103 |
gradio_app = gr.Interface(
|
104 |
fn=predict_and_plot,
|