A simple FastAPI-based threat detection API that uses a trained model to predict if network traffic is malicious based on the number of bytes transferred.
Suresh
This project is a minimal implementation of a machine learning model served using FastAPI. It accepts a value for bytes_transferred and returns a prediction with a confidence score on whether the network traffic is malicious.
- FastAPI: for building the API
- Joblib: for model loading
- Scikit-learn: for the ML model (RandomForest)
- Uvicorn: ASGI server to run FastAPI
.
├── app
│ ├── main.py # Main FastAPI app
│ └── model.pkl # Trained model file
├── requirements.txt # Python dependencies
├── README.md
└── .gitignore
- Method: POST
- Request Body:
{
"bytes_transferred": 4500
}- Response:
{
"verdict": "benign",
"confidence": 0.87
}- Clone the repo:
git clone https://github.com/suri10/ai-threat-detector.git
cd ai-threat-detector- Create a virtual environment:
python -m venv venv
source venv/bin/activate # or .\venv\Scripts\activate on Windows- Install dependencies:
pip install -r requirements.txt- Run the app:
uvicorn app.main:app --reload- Build and test prediction model
- Create FastAPI app
- Connect
/predictendpoint - Set up for GitHub upload
- Deploy to cloud (Future)
Pull requests are welcome!
This project is open source and available under the MIT License.
Let's catch threats with AI! 💻⚡