Update app.py
Browse files
app.py
CHANGED
|
@@ -433,18 +433,23 @@ def main_ui():
|
|
| 433 |
map_output = gr.HTML(label="Prediction Map")
|
| 434 |
|
| 435 |
clear_btn = gr.Button("Clear Session")
|
| 436 |
-
|
|
|
|
| 437 |
def on_add_point(date, time_inp, loc_text):
|
| 438 |
-
|
|
|
|
| 439 |
|
| 440 |
def on_train(trace_str):
|
|
|
|
| 441 |
traces = [parse_trace_text(trace_str)]
|
|
|
|
| 442 |
model = train_model_on_traces(traces)
|
| 443 |
if model:
|
| 444 |
return "Training completed."
|
| 445 |
else:
|
| 446 |
return "Training failed or insufficient data."
|
| 447 |
|
|
|
|
| 448 |
def on_predict():
|
| 449 |
if not SESSION_POINTS or len(SESSION_POINTS) < SEQ_LEN:
|
| 450 |
return "Not enough points for prediction.", ""
|
|
@@ -457,10 +462,10 @@ def main_ui():
|
|
| 457 |
map_html = make_map_html(last_lat, last_lon, preds)
|
| 458 |
return explanation, map_html
|
| 459 |
|
| 460 |
-
add_btn.click(on_add_point, inputs=[date_input, time_input, loc_input], outputs=add_status)
|
| 461 |
train_btn.click(on_train, inputs=[trace_text], outputs=train_status)
|
| 462 |
predict_btn.click(on_predict, outputs=[predict_output, map_output])
|
| 463 |
-
clear_btn.click(lambda: clear_session(), outputs=add_status)
|
| 464 |
|
| 465 |
return demo
|
| 466 |
|
|
|
|
| 433 |
map_output = gr.HTML(label="Prediction Map")
|
| 434 |
|
| 435 |
clear_btn = gr.Button("Clear Session")
|
| 436 |
+
point_counter = gr.Textbox(label="Current # of Points", interactive=False)
|
| 437 |
+
|
| 438 |
def on_add_point(date, time_inp, loc_text):
|
| 439 |
+
msg = add_point(date, time_inp, loc_text)
|
| 440 |
+
return msg, f"{len(SESSION_POINTS)}"
|
| 441 |
|
| 442 |
def on_train(trace_str):
|
| 443 |
+
global SESSION_POINTS
|
| 444 |
traces = [parse_trace_text(trace_str)]
|
| 445 |
+
SESSION_POINTS = traces[0] if traces and len(traces[0]) >= SEQ_LEN else []
|
| 446 |
model = train_model_on_traces(traces)
|
| 447 |
if model:
|
| 448 |
return "Training completed."
|
| 449 |
else:
|
| 450 |
return "Training failed or insufficient data."
|
| 451 |
|
| 452 |
+
|
| 453 |
def on_predict():
|
| 454 |
if not SESSION_POINTS or len(SESSION_POINTS) < SEQ_LEN:
|
| 455 |
return "Not enough points for prediction.", ""
|
|
|
|
| 462 |
map_html = make_map_html(last_lat, last_lon, preds)
|
| 463 |
return explanation, map_html
|
| 464 |
|
| 465 |
+
add_btn.click(on_add_point, inputs=[date_input, time_input, loc_input], outputs=[add_status, point_counter])
|
| 466 |
train_btn.click(on_train, inputs=[trace_text], outputs=train_status)
|
| 467 |
predict_btn.click(on_predict, outputs=[predict_output, map_output])
|
| 468 |
+
clear_btn.click(lambda: (clear_session(), "0"), outputs=[add_status, point_counter])
|
| 469 |
|
| 470 |
return demo
|
| 471 |
|