Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
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 |
-
#
|
177 |
-
|
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)
|