robocan commited on
Commit
2355c91
·
verified ·
1 Parent(s): c703504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
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
- return gr.BarPlot(
83
- data,
84
- x="Location",
85
- y="Probability",
86
- title="Top 10 Predictions with Probabilities",
87
- tooltip=["Location", "Probability"],
88
- y_lim=[0, max_prob],
89
- width=400, # Set the width of the plot
90
- height=300 # Set the height of the plot
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,