Download app.py from mohit9805/ids_model: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/spaces/mohit9805/ids_model/resolve/main/app.py
- Command line
-
hf download hf://spaces/mohit9805/ids_model/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mohit9805/ids_model/resolve/main/app.py
802 Bytes
| import pickle | |
| import cloudpickle | |
| import gradio as gr | |
| import pandas as pd | |
| # Load pipeline and features | |
| with open("IDS_Pipeline.pkl", "rb") as f: | |
| model = pickle.load(f) | |
| with open("feature_names.pkl", "rb") as f: | |
| feature_names = cloudpickle.load(f) | |
| # Prediction function | |
| def predict(file): | |
| df = pd.read_csv(file) | |
| df = df[feature_names] | |
| preds = model.predict(df) # corrected from pipeline.predict | |
| df["Prediction"] = preds | |
| return df | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.File(type="file", label="Upload CSV file"), | |
| outputs=gr.Dataframe(label="Predictions"), | |
| title="Intrusion Detection System", | |
| description="Upload a CSV file with features. The model will predict if it's Normal or Attack." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |