A FastAPI-based AI web application for real-time cyberattack detection using a trained machine learning model. It provides an interactive web interface for users to input network traffic features and receive live predictions on whether the traffic is Benign or an Attack.
- ✅ Built with FastAPI for high-speed performance
- 🔍 Predicts attacks using a trained scikit-learn model
- 📈 Uses a StandardScaler for input feature normalization
- 🧠 Dynamic input form generated from
features.pkl
- 💡 User-friendly web interface with Jinja2 templates
- 🧪 Robust error handling and form validation
cyberattack-detector-AI/
│
├── main.py # FastAPI backend
├── model.pkl # Trained ML model
├── scaler.pkl # Fitted StandardScaler
├── features.pkl # List of input features
├── templates/
│ └── index.html # Web form and result display
├── static/ # CSS or image assets (optional)
└── README.md # This file
-
Clone the repository
git clone https://github.com/your-username/cyberattack-detector-AI.git cd cyberattack-detector-AI
-
Install required packages
pip install -r requirements.txt
-
Run the application
uvicorn main:app --reload
-
Access the app Open your browser and go to:
👉http://127.0.0.1:8000
- Loads the ML model, scaler, and feature list.
- Renders a form with all required feature fields.
- On form submission:
- Values are collected and scaled.
- The model makes a prediction.
- The result is displayed as Benign or Attack.
- Python 3.8+
- FastAPI
- Uvicorn
- scikit-learn
- joblib
- Jinja2
Install all requirements:
pip install fastapi uvicorn scikit-learn joblib jinja2
This project is licensed under the MIT License
Muhammad Saeed
AI & Machine Learning & IoT Enthusiast