Spaces:
Runtime error
Runtime error
A newer version of the Gradio SDK is available: 6.14.0
metadata
title: Network Intrusion Detection System
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
pinned: false
license: mit
tags:
- ml-intern
π‘οΈ Network Intrusion Detection System (NIDS)
Real-time network intrusion detection using ML & Deep Learning models trained on the NSL-KDD dataset.
Models
- XGBoost (best) β Accuracy 76.18%, AUC-ROC 95.75%
- Random Forest β Accuracy 73.10%, AUC-ROC 95.34%
- MLP β Deep learning baseline
- Autoencoder β Unsupervised anomaly detection
- LSTM β Sequential feature modeling
- Transformer β FlowTransformer-style architecture
Dataset
NSL-KDD β 185K records, 41 features, binary classification (normal/anomaly)
Usage
REST API (FastAPI)
pip install fastapi uvicorn
uvicorn api:app --host 0.0.0.0 --port 8000
Endpoints:
GET /healthβ Health checkGET /modelsβ List modelsPOST /predictβ Single flow detectionPOST /predict/batchβ Batch detectionGET /statsβ Usage statistics
Gradio UI
python app.py
API Example
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"features":[0,1,45,0,491,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,2,2,0,0,0,0,1,0,0,0,0.17], "model":"XGBoost"}'
Results
| Model | Accuracy | Macro F1 | AUC-ROC | Type |
|---|---|---|---|---|
| XGBoost | 76.18% | 76.04% | 95.75% | Supervised |
| RandomForest | 73.10% | 73.05% | 95.34% | Supervised |
| MLP | 73.28% | 73.21% | 89.33% | Supervised |
| Autoencoder | 71.84% | 71.34% | 73.60% | Unsupervised |
| LSTM | 70.65% | 70.58% | 87.80% | Unsupervised |
| Transformer | 57.94% | 57.26% | 80.29% | Supervised |
| IsolationForest | 56.55% | 55.96% | 65.24% | Unsupervised |
Project Structure
nids_project/
βββ api.py # FastAPI REST API
βββ app.py # Gradio web UI (this Space)
βββ data_loader.py # Dataset loading
βββ ml_models.py # ML implementations
βββ dl_models.py # DL implementations
βββ realtime.py # Real-time pipeline
βββ realtime_batch.py # Batch throughput benchmark
βββ Dockerfile # Container image
βββ requirements.txt # Dependencies