Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -398,7 +398,7 @@ def calculate_distance_metrics(y_true, y_pred):
|
|
398 |
# Classical Metrics Prediction
|
399 |
# ============================
|
400 |
|
401 |
-
def classical_prediction(
|
402 |
"""
|
403 |
Preprocess the input CSV and make predictions using the selected model.
|
404 |
Calculate classical evaluation metrics and include inference time.
|
@@ -408,7 +408,7 @@ def classical_prediction(file, model_choice, min_mmsi, max_mmsi, models, loaded_
|
|
408 |
|
409 |
# Load the uploaded CSV file and filter based on MMSI
|
410 |
logging.info("Loading uploaded CSV file...")
|
411 |
-
df = pd.read_csv(
|
412 |
logging.info(f"Uploaded CSV file loaded with {df.shape[0]} records.")
|
413 |
|
414 |
df = df[(df['mmsi'] >= min_mmsi) & (df['mmsi'] <= max_mmsi)]
|
@@ -557,7 +557,7 @@ def classical_prediction(file, model_choice, min_mmsi, max_mmsi, models, loaded_
|
|
557 |
# Abnormal Behavior Detection
|
558 |
# ============================
|
559 |
|
560 |
-
def abnormal_behavior_detection(
|
561 |
"""
|
562 |
Detect abnormal behavior based on angular divergence and distance difference.
|
563 |
Accepts a CSV file containing real and predicted positions.
|
@@ -567,7 +567,7 @@ def abnormal_behavior_detection(prediction_file, alpha=0.5, threshold=10.0):
|
|
567 |
|
568 |
# Load the CSV file containing real and predicted positions
|
569 |
logging.info("Loading prediction CSV file...")
|
570 |
-
df = pd.read_csv(
|
571 |
logging.info(f"Prediction CSV file loaded with {df.shape[0]} records.")
|
572 |
|
573 |
# Check if necessary columns exist
|
@@ -691,7 +691,7 @@ def main():
|
|
691 |
classical_tab = gr.Interface(
|
692 |
fn=lambda file, model_choice, min_mmsi, max_mmsi: classical_prediction(file, model_choice, min_mmsi, max_mmsi, models, loaded_scalers),
|
693 |
inputs=[
|
694 |
-
gr.File(label="Upload CSV File", type='
|
695 |
gr.Dropdown(choices=["Auto-Select", "Teacher", "Student_North", "Student_Mid", "Student_South"], value="Auto-Select", label="Choose Model"),
|
696 |
gr.Number(label="Min MMSI", value=0),
|
697 |
gr.Number(label="Max MMSI", value=999999999)
|
@@ -709,7 +709,7 @@ def main():
|
|
709 |
abnormal_tab = gr.Interface(
|
710 |
fn=lambda prediction_file, alpha, threshold: abnormal_behavior_detection(prediction_file, alpha, threshold),
|
711 |
inputs=[
|
712 |
-
gr.File(label="Upload Predicted Positions CSV", type='
|
713 |
gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label="Alpha (α)"),
|
714 |
gr.Number(label="Threshold", value=10.0)
|
715 |
],
|
|
|
398 |
# Classical Metrics Prediction
|
399 |
# ============================
|
400 |
|
401 |
+
def classical_prediction(file_path, model_choice, min_mmsi, max_mmsi, models, loaded_scalers):
|
402 |
"""
|
403 |
Preprocess the input CSV and make predictions using the selected model.
|
404 |
Calculate classical evaluation metrics and include inference time.
|
|
|
408 |
|
409 |
# Load the uploaded CSV file and filter based on MMSI
|
410 |
logging.info("Loading uploaded CSV file...")
|
411 |
+
df = pd.read_csv(file_path, delimiter=',')
|
412 |
logging.info(f"Uploaded CSV file loaded with {df.shape[0]} records.")
|
413 |
|
414 |
df = df[(df['mmsi'] >= min_mmsi) & (df['mmsi'] <= max_mmsi)]
|
|
|
557 |
# Abnormal Behavior Detection
|
558 |
# ============================
|
559 |
|
560 |
+
def abnormal_behavior_detection(prediction_file_path, alpha=0.5, threshold=10.0):
|
561 |
"""
|
562 |
Detect abnormal behavior based on angular divergence and distance difference.
|
563 |
Accepts a CSV file containing real and predicted positions.
|
|
|
567 |
|
568 |
# Load the CSV file containing real and predicted positions
|
569 |
logging.info("Loading prediction CSV file...")
|
570 |
+
df = pd.read_csv(prediction_file_path)
|
571 |
logging.info(f"Prediction CSV file loaded with {df.shape[0]} records.")
|
572 |
|
573 |
# Check if necessary columns exist
|
|
|
691 |
classical_tab = gr.Interface(
|
692 |
fn=lambda file, model_choice, min_mmsi, max_mmsi: classical_prediction(file, model_choice, min_mmsi, max_mmsi, models, loaded_scalers),
|
693 |
inputs=[
|
694 |
+
gr.File(label="Upload CSV File", type='filepath'),
|
695 |
gr.Dropdown(choices=["Auto-Select", "Teacher", "Student_North", "Student_Mid", "Student_South"], value="Auto-Select", label="Choose Model"),
|
696 |
gr.Number(label="Min MMSI", value=0),
|
697 |
gr.Number(label="Max MMSI", value=999999999)
|
|
|
709 |
abnormal_tab = gr.Interface(
|
710 |
fn=lambda prediction_file, alpha, threshold: abnormal_behavior_detection(prediction_file, alpha, threshold),
|
711 |
inputs=[
|
712 |
+
gr.File(label="Upload Predicted Positions CSV", type='filepath'),
|
713 |
gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label="Alpha (α)"),
|
714 |
gr.Number(label="Threshold", value=10.0)
|
715 |
],
|