Spaces:
Sleeping
Sleeping
Deploy FastAPI to Hugging Face
Browse files- README.md +7 -165
- READ_ME.md +0 -10
README.md
CHANGED
|
@@ -1,168 +1,10 @@
|
|
| 1 |
-
# 📱 Telecom Anomaly Detection System
|
| 2 |
-
|
| 3 |
-
A production-ready anomaly detection system for telecommunications Call Data Records (CDR). This system identifies unusual patterns in subscriber behavior, ranging from potential fraud to technical malfunctions.
|
| 4 |
-
|
| 5 |
-
## 🚀 How it Works
|
| 6 |
-
|
| 7 |
-
The system operates as an automated pipeline that transforms raw CDR data into actionable security insights:
|
| 8 |
-
|
| 9 |
-
1. **Data Ingestion**: Reads CSV files from the `data/input` directory or direct CLI arguments.
|
| 10 |
-
2. **Validation & Cleaning**: Filters out invalid records, parses dates/times, and categorizes calls (e.g., voice vs. SMS, service vs. subscriber).
|
| 11 |
-
3. **Multi-Layered Detection**: Parallel analysis of each record across multiple specialized detector modules.
|
| 12 |
-
4. **Anomaly Aggregation**: Combines findings per subscriber and per record, calculating confidence scores and eliminating duplicates.
|
| 13 |
-
5. **Reporting**: Generates multiple output formats for different stakeholders (analysts, systems, executives).
|
| 14 |
-
|
| 15 |
---
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
| :--- | :--- | :--- |
|
| 23 |
-
| **Duration** | Monitors for "infinite calls" or "flash calls" | Fraud, billing errors |
|
| 24 |
-
| **Frequency** | Tracks calls per minute/hour/day | Automated dialing, SMS flooding |
|
| 25 |
-
| **SMS** | Specifically analyzes SMS volume and rate | Spam, bulk-SMS marketing |
|
| 26 |
-
| **Location** | Calculates velocity between consecutive activities | Account sharing, travel anomalies |
|
| 27 |
-
| **IMEI** | Tracks hardware-to-subscriber changes | SIM swapping, device theft |
|
| 28 |
-
| **Time Pattern** | Identifies activity during unusual (night) hours | Targeted attacks, outlier behavior |
|
| 29 |
-
|
| 30 |
---
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
The project follows a modular orchestrator-based architecture:
|
| 35 |
-
|
| 36 |
-
- **`TelecomAnomalyDetector` (Core)**: The central brain that coordinates the reader, validator, and all detector modules.
|
| 37 |
-
- **`TelecomDataReader`**: Handles high-performance batch reading of large CSV files.
|
| 38 |
-
- **`DataValidator`**: Ensures MSISDN formats, geographical coordinates, and timestamps are valid.
|
| 39 |
-
- **`ResultExporter`**: Formats findings into JSON (for APIs), CSV (for Excel), and Markdown (for reports).
|
| 40 |
-
|
| 41 |
-
---
|
| 42 |
-
|
| 43 |
-
## 📊 Data Requirements
|
| 44 |
-
|
| 45 |
-
The system expects CSV files with the following core columns:
|
| 46 |
-
|
| 47 |
-
- `msisdn`: Subscriber identification (e.g., `233XXXXXXXXX`)
|
| 48 |
-
- `usage_type`: `VOICE` or `SMS`
|
| 49 |
-
- `duration`: Call length in seconds
|
| 50 |
-
- `latitude` / `longitude`: Geographical coordinates of the activity
|
| 51 |
-
- `date` / `time`: Activity timestamps (`YYYY-MM-DD` and `HH:MM:SS`)
|
| 52 |
-
- `imei`: Device hardware identifier
|
| 53 |
-
|
| 54 |
-
---
|
| 55 |
-
|
| 56 |
-
## ⚙️ Configuration
|
| 57 |
-
|
| 58 |
-
Detection sensitivity can be tuned in `config/settings.py` or via `TelecomConfig` overrides:
|
| 59 |
-
|
| 60 |
-
```python
|
| 61 |
-
DEFAULT_THRESHOLDS = {
|
| 62 |
-
'extreme_call_threshold': 10800.0, # 3 hours
|
| 63 |
-
'max_calls_per_hour': 60, # >1 call/minute
|
| 64 |
-
'max_location_change_speed': 1000.0,# km/h (impossible travel)
|
| 65 |
-
'night_hours_start': 23, # Start of "unusual" hours
|
| 66 |
-
}
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
---
|
| 70 |
-
|
| 71 |
-
## 💻 Installation & Usage
|
| 72 |
-
|
| 73 |
-
### Setup with uv
|
| 74 |
-
The project uses [uv](https://github.com/astral-sh/uv) for high-performance dependency management.
|
| 75 |
-
|
| 76 |
-
```bash
|
| 77 |
-
# Clone and enter the repository
|
| 78 |
-
git clone https://github.com/yourusername/telecom-anomaly-detection.git
|
| 79 |
-
cd telecom-anomaly-detection
|
| 80 |
-
|
| 81 |
-
# Sync dependencies and create virtual environment
|
| 82 |
-
uv sync
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
### Running the Analysis
|
| 86 |
-
Place your CSV files in `data/input/` and run using `uv run`:
|
| 87 |
-
```bash
|
| 88 |
-
uv run python -m telecom_anomaly.main
|
| 89 |
-
```
|
| 90 |
-
|
| 91 |
-
Or specify files directly:
|
| 92 |
-
```bash
|
| 93 |
-
uv run python -m telecom_anomaly.main data/input/records_2023_10.csv
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
### Development
|
| 97 |
-
```bash
|
| 98 |
-
# Run tests
|
| 99 |
-
uv run pytest
|
| 100 |
-
|
| 101 |
-
# Format code
|
| 102 |
-
uv run black .
|
| 103 |
-
|
| 104 |
-
# Lint code
|
| 105 |
-
uv run flake8 .
|
| 106 |
-
```
|
| 107 |
-
|
| 108 |
-
## 🌐 API (FastAPI)
|
| 109 |
-
|
| 110 |
-
The project includes a FastAPI-based REST API for programmatic access to the anomaly detection engine.
|
| 111 |
-
|
| 112 |
-
### Running the API
|
| 113 |
-
```bash
|
| 114 |
-
uv run python -m uvicorn telecom_anomaly.api:app --reload
|
| 115 |
-
```
|
| 116 |
-
The API will be available at `http://127.0.0.1:8000`.
|
| 117 |
-
|
| 118 |
-
### API Documentation
|
| 119 |
-
Interactive documentation is available at:
|
| 120 |
-
- Swagger UI: `http://127.0.0.1:8000/docs`
|
| 121 |
-
- ReDoc: `http://127.0.0.1:8000/redoc`
|
| 122 |
-
|
| 123 |
-
### Key Endpoints
|
| 124 |
-
|
| 125 |
-
#### `POST /analyze`
|
| 126 |
-
Upload a CDR CSV file for real-time analysis.
|
| 127 |
-
|
| 128 |
-
**Example using curl:**
|
| 129 |
-
```bash
|
| 130 |
-
curl -X 'POST' \
|
| 131 |
-
'http://127.0.0.1:8000/analyze' \
|
| 132 |
-
-H 'accept: application/json' \
|
| 133 |
-
-H 'Content-Type: multipart/form-data' \
|
| 134 |
-
-F 'file=@data/input/sample_cdr.csv'
|
| 135 |
-
```
|
| 136 |
-
|
| 137 |
-
**Response Example:**
|
| 138 |
-
```json
|
| 139 |
-
{
|
| 140 |
-
"filename": "sample_cdr.csv",
|
| 141 |
-
"statistics": {
|
| 142 |
-
"total_rows": 1000,
|
| 143 |
-
"rows_with_anomalies": 15,
|
| 144 |
-
"total_anomalies_detected": 22,
|
| 145 |
-
"anomaly_rate": 1.5,
|
| 146 |
-
"unique_subscribers": 12,
|
| 147 |
-
"anomaly_types": {
|
| 148 |
-
"short_duration": 10,
|
| 149 |
-
"impossible_speed": 5
|
| 150 |
-
}
|
| 151 |
-
},
|
| 152 |
-
"anomalies": [
|
| 153 |
-
{
|
| 154 |
-
"row_index": 42,
|
| 155 |
-
"column_name": "duration",
|
| 156 |
-
"value": 1.2,
|
| 157 |
-
"detection_method": "short_duration",
|
| 158 |
-
"score": 2.5,
|
| 159 |
-
"threshold": 3.0,
|
| 160 |
-
"confidence": 0.75,
|
| 161 |
-
"msisdn": "233123456789"
|
| 162 |
-
}
|
| 163 |
-
]
|
| 164 |
-
}
|
| 165 |
-
```
|
| 166 |
-
|
| 167 |
-
#### `GET /health`
|
| 168 |
-
Returns the health status of the API.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Teleprocessinggh
|
| 3 |
+
emoji: 🏢
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
READ_ME.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Teleprocessinggh
|
| 3 |
-
emoji: 🏢
|
| 4 |
-
colorFrom: pink
|
| 5 |
-
colorTo: yellow
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|