robocan commited on
Commit
52895be
1 Parent(s): 940a536

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -29,8 +29,7 @@ device = 'cpu'
29
  le = LabelEncoder()
30
  le = joblib.load("SVD/le.gz")
31
  len_classes = len(le.classes_) + 1
32
- # Global variable to store predictions for dynamic zoom
33
- global_predictions = None
34
 
35
  class ModelPre(torch.nn.Module):
36
  def __init__(self):
@@ -147,7 +146,7 @@ def create_label_output(predictions):
147
  results, cell_ids = predictions
148
  fig = create_map_figure(results, cell_ids)
149
  return fig
150
-
151
  def predict_and_plot(input_img, selected_prediction):
152
  predictions = predict(input_img)
153
 
@@ -166,15 +165,12 @@ def predict_and_plot(input_img, selected_prediction):
166
  with gr.Blocks() as gradio_app:
167
  with gr.Column():
168
  input_image = gr.Image(label="Upload an Image", type="pil")
 
169
  output_map = gr.Plot(label="Predicted Location on Map")
170
  btn_predict = gr.Button("Predict")
171
- selected_prediction = gr.Dropdown(choices=[f"Prediction {i+1}" for i in range(10)], label="Select Prediction to Zoom", value=None)
172
-
173
- # Perform the prediction and plot the initial map
174
- btn_predict.click(predict, inputs=input_image, outputs=output_map)
175
 
176
- # Allow the user to zoom in on a selected prediction after the prediction is made
177
- selected_prediction.change(zoom_on_prediction, inputs=selected_prediction, outputs=output_map)
178
 
179
  examples = ["GB.PNG", "IT.PNG", "NL.PNG", "NZ.PNG"]
180
  gr.Examples(examples=examples, inputs=input_image)
 
29
  le = LabelEncoder()
30
  le = joblib.load("SVD/le.gz")
31
  len_classes = len(le.classes_) + 1
32
+
 
33
 
34
  class ModelPre(torch.nn.Module):
35
  def __init__(self):
 
146
  results, cell_ids = predictions
147
  fig = create_map_figure(results, cell_ids)
148
  return fig
149
+
150
  def predict_and_plot(input_img, selected_prediction):
151
  predictions = predict(input_img)
152
 
 
165
  with gr.Blocks() as gradio_app:
166
  with gr.Column():
167
  input_image = gr.Image(label="Upload an Image", type="pil")
168
+ selected_prediction = gr.Dropdown(choices=[f"Prediction {i+1}" for i in range(10)], label="Select Prediction to Zoom", value=None)
169
  output_map = gr.Plot(label="Predicted Location on Map")
170
  btn_predict = gr.Button("Predict")
 
 
 
 
171
 
172
+ # Update click function to include selected prediction
173
+ btn_predict.click(predict_and_plot, inputs=[input_image, selected_prediction], outputs=output_map)
174
 
175
  examples = ["GB.PNG", "IT.PNG", "NL.PNG", "NZ.PNG"]
176
  gr.Examples(examples=examples, inputs=input_image)