robocan commited on
Commit
8a4658f
1 Parent(s): 9678900

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
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=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
 
 
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