Spaces:
Sleeping
Sleeping
File size: 5,163 Bytes
c7281c7 a7252f1 c7281c7 a7252f1 c7281c7 a7252f1 c7281c7 a7252f1 c7281c7 a7252f1 c7281c7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | ---
title: Amide Models
emoji: 🔬
colorFrom: blue
colorTo: indigo
sdk: docker
app_file: app.py
pinned: false
---
# Amide Models - Breach Prediction API
A Flask-based API for network breach prediction using multiple machine learning models.
## Overview
This project provides a REST API for predicting network security breaches using three different machine learning models:
- **LightGBM**: Gradient boosting model for breach classification
- **Autoencoder**: Deep learning model for anomaly detection
- **XGB-LSTM**: Hybrid XGBoost and LSTM model for sequence prediction
## Features
- REST API endpoints for model inference
- Support for multiple ML models
- Input validation and error handling
- Health check endpoint
- Model information endpoint
- Docker containerized deployment
## API Endpoints
### GET `/health`
Health check endpoint to verify the service is running.
**Response:**
```json
{
"status": "healthy"
}
```
### GET `/models`
Returns available models and their configuration.
**Response:**
```json
{
"available_models": {
"lightGBM": {
"file": "lightGBM.py",
"available": true,
"interface": "hardcoded"
},
"autoencoder": {
"file": "autoencoder.py",
"available": true,
"interface": "hardcoded"
},
"XGB_lstm": {
"file": "XGB_lstm.py",
"available": true,
"interface": "argparse"
}
},
"required_columns": ["timestamp", "src_ip", "dst_ip", "src_port", "dst_port"]
}
```
### POST `/compute`
Run breach prediction using **all 3 models simultaneously** on network logs.
**Request:**
```json
{
"file": [
{
"timestamp": "2024-01-01T10:00:00",
"src_ip": "192.168.1.100",
"dst_ip": "10.0.0.1",
"src_port": 12345,
"dst_port": 80,
"packet_size": 1500,
"seq": 1000,
"ack": 2000,
"tcp_flags": 2,
"window": 65535
},
{
"timestamp": "2024-01-01T10:00:01",
"src_ip": "192.168.1.101",
"dst_ip": "10.0.0.2",
"src_port": 12346,
"dst_port": 443,
"packet_size": 1500,
"seq": 1001,
"ack": 2001,
"tcp_flags": 2,
"window": 65535
}
]
}
```
**Response:**
```json
{
"success": true,
"packets": {
"total": 2,
"unique_flows": 2
},
"models": {
"lightGBM": {
"success": true,
"output": "Model execution output",
"predictions": [
{
"timestamp": "2024-01-01T10:00:00",
"src_ip": "192.168.1.100",
"breach_probability": 0.95,
"breach_predicted": 1
}
],
"error": null
},
"autoencoder": {
"success": true,
"output": "Model execution output",
"predictions": [
{
"timestamp": "2024-01-01T10:00:00",
"anomaly_score": 0.87,
"is_anomaly": true
}
],
"error": null
},
"XGB_lstm": {
"success": true,
"output": "Model execution output",
"predictions": [
{
"timestamp": "2024-01-01T10:00:00",
"breach_risk": 0.92,
"prediction": 1
}
],
"error": null
}
}
}
```
**Response Format:**
- `success`: Overall success status (all models succeeded)
- `packets.total`: Total number of packets in the request
- `packets.unique_flows`: Number of unique network flows (src_ip:src_port → dst_ip:dst_port)
- `models`: Dictionary containing results from each model with the same name as the model
- Each model includes: `success` (bool), `output` (stdout), `predictions` (array), `error` (stderr)
## Required Input Columns
- `timestamp`: Timestamp of the network flow
- `src_ip`: Source IP address
- `dst_ip`: Destination IP address
- `src_port`: Source port
- `dst_port`: Destination port
Additional columns like `packet_size`, `seq`, `ack` are recommended for better predictions.
## Installation
### Local Setup
```bash
pip install -r requirements.txt
python app.py
```
The API will be available at `http://localhost:5000`
### Docker Setup
```bash
docker build -t amide-models .
docker run -p 5000:5000 amide-models
```
## Requirements
- Python 3.8+
- Flask
- Flask-CORS
- pandas
- numpy
- scikit-learn
- tensorflow
- lightgbm
- xgboost
See `requirements.txt` for all dependencies.
## Models
### LightGBM
Gradient boosting classifier optimized for network breach detection with 60% threshold for breach classification.
### Autoencoder
Deep learning model using autoencoders to detect anomalous network patterns.
### XGB-LSTM
Hybrid model combining XGBoost with LSTM for temporal sequence analysis of network flows.
## Output
All models generate predictions with:
- Breach probability score (0-1)
- Binary breach prediction (0 or 1)
- Confidence metrics
## Development
To modify or add new models:
1. Create a new Python file with your model
2. Update `MODEL_CONFIGS` in `app.py` with the new model configuration
3. Ensure your model can accept input via:
- Hardcoded filename: reads from `network_logs.csv`
- Argparse: accepts `--logfile` command-line argument
## License
MIT
## Contact
For issues and questions, please check the repository documentation.
|