Spaces:
Sleeping
Sleeping
| import joblib | |
| import pandas as pd | |
| def load_artifacts(): | |
| """Load the trained pipeline and target encoder.""" | |
| pipeline = joblib.load("models/network_logs_pipeline.joblib") | |
| target_encoder = joblib.load("models/target_encoder.joblib") | |
| return pipeline, target_encoder | |
| def predict_intrusion(pipeline, target_encoder, features: dict): | |
| """ | |
| Predict Scan_Type from input features. | |
| Args: | |
| pipeline: sklearn pipeline with preprocessing + model | |
| target_encoder: LabelEncoder for Scan_Type | |
| features: dict of input features | |
| Returns: | |
| str: Predicted Scan_Type | |
| """ | |
| input_df = pd.DataFrame([features]) # single row DataFrame | |
| pred_label = pipeline.predict(input_df)[0] | |
| scan_type = target_encoder.inverse_transform([pred_label])[0] | |
| return scan_type | |