barathvasan-dev commited on
Commit
7bbf985
ยท
1 Parent(s): fb7f78e

docs: comprehensive README with security features and architecture

Browse files
Files changed (1) hide show
  1. README.md +177 -1
README.md CHANGED
@@ -11,4 +11,180 @@ pinned: false
11
  license: mit
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  license: mit
12
  ---
13
 
14
+ # ๐Ÿš— Vehicle Intelligence System
15
+
16
+ Advanced license plate detection, OCR, and natural language database querying system with security hardening.
17
+
18
+ ## ๐ŸŽฏ Features
19
+
20
+ ### Detection Pipeline
21
+ - ๐ŸŽฅ **YOLO Plate Detection** - Real-time license plate localization
22
+ - ๐Ÿ”ค **PaddleOCR** - High-accuracy OCR for plate text extraction
23
+ - ๐Ÿš— **Vehicle Classification** - Classify vehicle types (car, truck, bike, etc.)
24
+ - ๐Ÿ›ก๏ธ **Confidence Scoring** - All detections include confidence metrics
25
+
26
+ ### Database & Analytics
27
+ - ๐Ÿ“Š **Supabase PostgreSQL** - Robust cloud database with automatic backups
28
+ - ๐Ÿ” **NLP-to-SQL** - Ask questions in natural language, AI converts to SQL
29
+ - ๐Ÿ›ก๏ธ **SQL Validation** - Prevents injection attacks and dangerous queries
30
+ - โšก **Optimized Indexes** - Fast queries with proper database indexing
31
+ - ๐Ÿ“ˆ **Real-time Analytics** - Dashboard with state distribution, hourly traffic, suspicious vehicles
32
+
33
+ ### Security Features
34
+ - โœ… **SQL Injection Prevention** - Whitelist/blacklist keyword validation
35
+ - ๐Ÿ”’ **Read-Only Queries** - Only SELECT queries allowed
36
+ - ๐Ÿ“ **Query History** - Track all database queries for audit
37
+ - ๐Ÿ” **State Extraction** - Automatically extract state codes from license plates
38
+
39
+ ## ๐Ÿ“‚ Modular Architecture
40
+
41
+ ```
42
+ plate-detector/
43
+ โ”œโ”€โ”€ app.py # Main Gradio UI with 3 tabs
44
+ โ”œโ”€โ”€ detector.py # YOLO, OCR, vehicle classification
45
+ โ”œโ”€โ”€ database.py # SQL validation, LLM, database operations
46
+ โ”œโ”€โ”€ requirements.txt # Python dependencies
47
+ โ””โ”€โ”€ .env # Environment variables (Supabase, HF token)
48
+ ```
49
+
50
+ ### Files Explained
51
+
52
+ **app.py** - Simplified UI layer
53
+ - Detection tab: Upload images, detect plates
54
+ - Database Query tab: NLP-to-SQL search with example queries
55
+ - Analytics tab: Real-time dashboard with metrics
56
+
57
+ **detector.py** - Computer Vision Module
58
+ - License plate detection using YOLO
59
+ - OCR using PaddleOCR
60
+ - Vehicle classification (10 types)
61
+ - State code extraction (TN, KA, KL, etc.)
62
+ - Image preprocessing and augmentation
63
+
64
+ **database.py** - Data & Security Layer
65
+ - SQL validation (blocks DELETE, UPDATE, INSERT, DROP)
66
+ - SQLCoder LLM integration for NLP-to-SQL
67
+ - Database initialization with improved schema
68
+ - Automatic index creation for performance
69
+ - Query history tracking
70
+ - Analytics functions (suspicious vehicles, hourly traffic, etc.)
71
+
72
+ ## ๐Ÿš€ Deployment
73
+
74
+ ### Environment Variables
75
+
76
+ Create `.env` file with:
77
+
78
+ ```
79
+ DATABASE_URL=postgresql://user:password@host:5432/postgres
80
+ HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
81
+ ```
82
+
83
+ ### Run Locally
84
+
85
+ ```bash
86
+ pip install -r requirements.txt
87
+ python app.py
88
+ ```
89
+
90
+ Visit: http://localhost:7860
91
+
92
+ ### Deploy on Hugging Face Spaces
93
+
94
+ 1. Push code to HF Spaces repository
95
+ 2. Add secrets in Settings:
96
+ - `DATABASE_URL` - Supabase connection string
97
+ - `HF_TOKEN` - Hugging Face API token
98
+
99
+ ## ๐Ÿ›ก๏ธ Security Measures
100
+
101
+ ### SQL Validation
102
+
103
+ ```python
104
+ ALLOWED_KEYWORDS = ["SELECT", "FROM", "WHERE", "COUNT", ...]
105
+ BLOCKED_KEYWORDS = ["DROP", "DELETE", "UPDATE", "INSERT", ...]
106
+
107
+ # Only SELECT queries allowed
108
+ # Blocks all dangerous operations
109
+ ```
110
+
111
+ ### Database Schema
112
+
113
+ ```sql
114
+ CREATE TABLE vehicle_logs (
115
+ id BIGSERIAL PRIMARY KEY,
116
+ timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
117
+ plate TEXT,
118
+ state TEXT,
119
+ vehicle_type TEXT,
120
+ vehicle_conf FLOAT,
121
+ camera_id TEXT,
122
+ location TEXT,
123
+ image_url TEXT,
124
+ date DATE,
125
+ hour INTEGER,
126
+ day TEXT
127
+ );
128
+ ```
129
+
130
+ ### Indexes for Performance
131
+
132
+ ```sql
133
+ CREATE INDEX idx_plate ON vehicle_logs(plate);
134
+ CREATE INDEX idx_state ON vehicle_logs(state);
135
+ CREATE INDEX idx_vehicle_type ON vehicle_logs(vehicle_type);
136
+ CREATE INDEX idx_timestamp ON vehicle_logs(timestamp);
137
+ CREATE INDEX idx_date ON vehicle_logs(date);
138
+ ```
139
+
140
+ ## ๐ŸŽฏ Example Queries
141
+
142
+ - "How many cars today?"
143
+ - "Show all trucks"
144
+ - "Count bikes"
145
+ - "Show TN vehicles"
146
+ - "Show vehicles after 6pm"
147
+ - "List latest 10 detections"
148
+ - "Count vehicles by type"
149
+ - "Show high confidence detections"
150
+ - "List all unique plates"
151
+ - "Show suspicious vehicles"
152
+
153
+ ## ๐Ÿ“Š Analytics Dashboard
154
+
155
+ - **Vehicles by State** - Distribution of detections across states
156
+ - **Traffic by Hour** - Hourly traffic patterns
157
+ - **Top Plates** - Most frequently detected license plates
158
+ - **Suspicious Vehicles** - High-frequency detections (>20 times)
159
+
160
+ ## ๐Ÿ”ฎ Future Improvements
161
+
162
+ - [ ] Vector search for similar plates
163
+ - [ ] Async database queries for better performance
164
+ - [ ] Image storage and retrieval
165
+ - [ ] Camera tracking and geolocation
166
+ - [ ] Result caching with Redis
167
+ - [ ] FastAPI backend separation
168
+ - [ ] React dashboard frontend
169
+
170
+ ## ๐Ÿ“ฆ Dependencies
171
+
172
+ - ultralytics - YOLO detection
173
+ - paddleocr - OCR
174
+ - transformers - Vehicle classification
175
+ - sqlalchemy - Database ORM
176
+ - huggingface-hub - LLM inference
177
+ - gradio - Web UI
178
+ - opencv - Image processing
179
+
180
+ ## ๐Ÿ“„ License
181
+
182
+ MIT License - See LICENSE file
183
+
184
+ ## ๐Ÿค Contributing
185
+
186
+ Contributions welcome! Please submit pull requests or issues.
187
+
188
+ ---
189
+
190
+ **Live Demo:** https://huggingface.co/spaces/BARATH0070/plate-detector