Samarth Naik commited on
Commit
c7281c7
·
1 Parent(s): 6e9f386

Add Hugging Face Spaces configuration and API documentation

Browse files
Files changed (1) hide show
  1. README.md +186 -0
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Amide Models
3
+ emoji: 🔬
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ app_file: app.py
8
+ pinned: false
9
+ ---
10
+
11
+ # Amide Models - Breach Prediction API
12
+
13
+ A Flask-based API for network breach prediction using multiple machine learning models.
14
+
15
+ ## Overview
16
+
17
+ This project provides a REST API for predicting network security breaches using three different machine learning models:
18
+
19
+ - **LightGBM**: Gradient boosting model for breach classification
20
+ - **Autoencoder**: Deep learning model for anomaly detection
21
+ - **XGB-LSTM**: Hybrid XGBoost and LSTM model for sequence prediction
22
+
23
+ ## Features
24
+
25
+ - REST API endpoints for model inference
26
+ - Support for multiple ML models
27
+ - Input validation and error handling
28
+ - Health check endpoint
29
+ - Model information endpoint
30
+ - Docker containerized deployment
31
+
32
+ ## API Endpoints
33
+
34
+ ### GET `/health`
35
+ Health check endpoint to verify the service is running.
36
+
37
+ **Response:**
38
+ ```json
39
+ {
40
+ "status": "healthy"
41
+ }
42
+ ```
43
+
44
+ ### GET `/models`
45
+ Returns available models and their configuration.
46
+
47
+ **Response:**
48
+ ```json
49
+ {
50
+ "available_models": {
51
+ "lightGBM": {
52
+ "file": "lightGBM.py",
53
+ "available": true,
54
+ "interface": "hardcoded"
55
+ },
56
+ "autoencoder": {
57
+ "file": "autoencoder.py",
58
+ "available": true,
59
+ "interface": "hardcoded"
60
+ },
61
+ "XGB_lstm": {
62
+ "file": "XGB_lstm.py",
63
+ "available": true,
64
+ "interface": "argparse"
65
+ }
66
+ },
67
+ "required_columns": ["timestamp", "src_ip", "dst_ip", "src_port", "dst_port"]
68
+ }
69
+ ```
70
+
71
+ ### POST `/compute`
72
+ Run breach prediction on network logs.
73
+
74
+ **Request:**
75
+ ```json
76
+ {
77
+ "model_type": "lightGBM",
78
+ "file": [
79
+ {
80
+ "timestamp": "2024-01-01T10:00:00",
81
+ "src_ip": "192.168.1.100",
82
+ "dst_ip": "10.0.0.1",
83
+ "src_port": 12345,
84
+ "dst_port": 80,
85
+ "packet_size": 1500,
86
+ "seq": 1000,
87
+ "ack": 2000
88
+ }
89
+ ]
90
+ }
91
+ ```
92
+
93
+ **Response:**
94
+ ```json
95
+ {
96
+ "success": true,
97
+ "output": "Model execution output",
98
+ "predictions": [
99
+ {
100
+ "timestamp": "2024-01-01T10:00:00",
101
+ "src_ip": "192.168.1.100",
102
+ "breach_probability": 0.95,
103
+ "breach_predicted": 1
104
+ }
105
+ ],
106
+ "error": null
107
+ }
108
+ ```
109
+
110
+ ## Required Input Columns
111
+
112
+ - `timestamp`: Timestamp of the network flow
113
+ - `src_ip`: Source IP address
114
+ - `dst_ip`: Destination IP address
115
+ - `src_port`: Source port
116
+ - `dst_port`: Destination port
117
+
118
+ Additional columns like `packet_size`, `seq`, `ack` are recommended for better predictions.
119
+
120
+ ## Installation
121
+
122
+ ### Local Setup
123
+
124
+ ```bash
125
+ pip install -r requirements.txt
126
+ python app.py
127
+ ```
128
+
129
+ The API will be available at `http://localhost:5000`
130
+
131
+ ### Docker Setup
132
+
133
+ ```bash
134
+ docker build -t amide-models .
135
+ docker run -p 5000:5000 amide-models
136
+ ```
137
+
138
+ ## Requirements
139
+
140
+ - Python 3.8+
141
+ - Flask
142
+ - Flask-CORS
143
+ - pandas
144
+ - numpy
145
+ - scikit-learn
146
+ - tensorflow
147
+ - lightgbm
148
+ - xgboost
149
+
150
+ See `requirements.txt` for all dependencies.
151
+
152
+ ## Models
153
+
154
+ ### LightGBM
155
+ Gradient boosting classifier optimized for network breach detection with 60% threshold for breach classification.
156
+
157
+ ### Autoencoder
158
+ Deep learning model using autoencoders to detect anomalous network patterns.
159
+
160
+ ### XGB-LSTM
161
+ Hybrid model combining XGBoost with LSTM for temporal sequence analysis of network flows.
162
+
163
+ ## Output
164
+
165
+ All models generate predictions with:
166
+ - Breach probability score (0-1)
167
+ - Binary breach prediction (0 or 1)
168
+ - Confidence metrics
169
+
170
+ ## Development
171
+
172
+ To modify or add new models:
173
+
174
+ 1. Create a new Python file with your model
175
+ 2. Update `MODEL_CONFIGS` in `app.py` with the new model configuration
176
+ 3. Ensure your model can accept input via:
177
+ - Hardcoded filename: reads from `network_logs.csv`
178
+ - Argparse: accepts `--logfile` command-line argument
179
+
180
+ ## License
181
+
182
+ MIT
183
+
184
+ ## Contact
185
+
186
+ For issues and questions, please check the repository documentation.