File size: 4,519 Bytes
961d2e4
 
 
 
 
 
 
 
 
 
b7e0c2d
6b6e83f
b7e0c2d
6b6e83f
b7e0c2d
 
 
 
 
6b6e83f
b7e0c2d
1a782a6
 
 
 
 
 
 
 
 
 
b7e0c2d
 
 
 
 
 
1a782a6
b7e0c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b6e83f
 
b7e0c2d
 
 
1a782a6
b7e0c2d
 
 
 
 
 
 
6b6e83f
 
b7e0c2d
 
 
 
 
 
6b6e83f
b7e0c2d
6b6e83f
 
b7e0c2d
 
 
 
 
 
 
6b6e83f
 
c5796c7
b7e0c2d
 
 
 
 
 
 
 
 
 
 
 
1a782a6
b7e0c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a782a6
 
b7e0c2d
 
 
 
1a782a6
 
b7e0c2d
 
 
 
 
 
 
 
 
 
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
---
title: Complaint Auto-Routing System
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 5.44.0
app_file: app.py
pinned: false
---

# Complaint Auto-Routing System

An end-to-end machine learning system that processes citizen complaints submitted in text, audio, or video format. It is designed to run fully offline without external APIs.

It automatically performs the following tasks:
- **Officer Routing**: Assigns the complaint to the most suitable officer from an internal list using an SVM.
- **Priority Prediction**: Classifies the priority as High, Medium, or Low using a Random Forest.
- **ETA Prediction**: Estimates resolution time in days using a Gradient Boosting Regressor.
- **Similarity Search**: Retrieves similar past complaints using cosine similarity over text embeddings.

---
## Project Screenshots
# Text Complaint 
<img width="1001" height="1279" alt="image" src="https://github.com/user-attachments/assets/681e20c1-a829-4f33-812e-c4296e170ece" />

# Audio Complaint 
<img width="992" height="1274" alt="image" src="https://github.com/user-attachments/assets/02e6677f-0c7c-4c49-9996-c5dcac5783f3" />

# Video Complaint 
<img width="984" height="1289" alt="image" src="https://github.com/user-attachments/assets/8cdc0fef-3699-4c48-bee3-84f76c2e9fb7" />


## Project Structure

```
complaint-routing-system/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ generate_data.py          # Synthetic complaint generator
β”‚   └── synthetic_complaints.csv  # 800 labelled complaints (auto-generated)
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ train.py                  # End-to-end training pipeline
β”‚   └── saved/                    # Trained model artifacts
β”œβ”€β”€ inference/
β”‚   β”œβ”€β”€ embedding_engine.py       # TF-IDF+SVD or sentence-transformers
β”‚   β”œβ”€β”€ vector_store.py           # NumPy cosine search
β”‚   └── engine.py                 # Core inference engine (load + predict)
β”œβ”€β”€ audio_video/
β”‚   └── transcriber.py            # Whisper-based offline ASR (audio + video)
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ cli.py                    # Command-line interface
β”‚   └── web_app.py                # Gradio web UI
β”œβ”€β”€ evaluation/
β”‚   └── evaluate.py               # Full evaluation suite
β”œβ”€β”€ requirements.txt
└── README.md
```

---

## Quick Start

### 1. Install dependencies

```bash
# Core requirements
pip install scikit-learn numpy pandas scipy joblib

# Embedding model
pip install sentence-transformers

# Web UI
pip install gradio

# Audio/Video transcription (requires ffmpeg installed on your system)
pip install openai-whisper
```

### 2. Generate training data and train models

```bash
python data/generate_data.py
python models/train.py
```

### 3. Run inference

```bash
# Interactive CLI
python app/cli.py

# Direct text
python app/cli.py --text "Pothole on MG Road near hospital causing accidents. URGENT!"

# Web UI
python app/web_app.py
```

### 4. Run evaluation

```bash
python evaluation/evaluate.py
```

---

## Architecture

The system takes in text, audio, or video. If audio or video is provided, it uses the local Whisper model to transcribe the speech offline.

The text is then passed to an embedding engine (using sentence-transformers). The resulting vector is passed to three separate scikit-learn models:
1. Support Vector Machine (Officer Routing)
2. Random Forest (Priority)
3. Gradient Boosting Regressor (ETA)

The vector is also compared against a local NumPy store of historical complaints using cosine similarity to fetch the most relevant past issues.

---

## Evaluation Results (5-fold Cross-Validation)

### Officer Routing (SVM)
| Metric | Value |
|--------|-------|
| CV Accuracy | 1.000 Β± 0.000 |
| CV F1-macro | 1.000 Β± 0.000 |

Note: The synthetic data has very clear departmental boundaries (e.g., "pothole" maps strictly to roads). In a real-world scenario, accuracy would be closer to 85-90%.

### Priority Prediction (Random Forest)
| Metric | Value |
|--------|-------|
| CV Accuracy | 0.578 Β± 0.014 |
| CV F1-macro | 0.566 Β± 0.020 |

### ETA Prediction (Gradient Boosting)
| Metric | Value |
|--------|-------|
| CV MAE | 5.25 days |
| CV RMSE | 7.62 days |

---

## Replacing Synthetic Data with Real Data

1. Prepare a CSV with columns: `text`, `officer_id`, `priority`, `eta_days`
2. Replace `data/synthetic_complaints.csv`
3. Run `python models/train.py`

The pipeline will automatically retrain all models on the new data and overwrite the old artifacts in `models/saved`.