Actionsync / README.md
barathvasan-dev
docs: comprehensive README with security features and architecture
7bbf985
|
Raw
History Blame Contribute Delete
5.17 kB

A newer version of the Gradio SDK is available: 6.26.0

Upgrade
metadata
title: Plate Detector
emoji: ๐Ÿƒ
colorFrom: gray
colorTo: gray
sdk: gradio
sdk_version: 6.14.0
python_version: '3.10'
app_file: app.py
pinned: false
license: mit

๐Ÿš— Vehicle Intelligence System

Advanced license plate detection, OCR, and natural language database querying system with security hardening.

๐ŸŽฏ Features

Detection Pipeline

  • ๐ŸŽฅ YOLO Plate Detection - Real-time license plate localization
  • ๐Ÿ”ค PaddleOCR - High-accuracy OCR for plate text extraction
  • ๐Ÿš— Vehicle Classification - Classify vehicle types (car, truck, bike, etc.)
  • ๐Ÿ›ก๏ธ Confidence Scoring - All detections include confidence metrics

Database & Analytics

  • ๐Ÿ“Š Supabase PostgreSQL - Robust cloud database with automatic backups
  • ๐Ÿ” NLP-to-SQL - Ask questions in natural language, AI converts to SQL
  • ๐Ÿ›ก๏ธ SQL Validation - Prevents injection attacks and dangerous queries
  • โšก Optimized Indexes - Fast queries with proper database indexing
  • ๐Ÿ“ˆ Real-time Analytics - Dashboard with state distribution, hourly traffic, suspicious vehicles

Security Features

  • โœ… SQL Injection Prevention - Whitelist/blacklist keyword validation
  • ๐Ÿ”’ Read-Only Queries - Only SELECT queries allowed
  • ๐Ÿ“ Query History - Track all database queries for audit
  • ๐Ÿ” State Extraction - Automatically extract state codes from license plates

๐Ÿ“‚ Modular Architecture

plate-detector/
โ”œโ”€โ”€ app.py              # Main Gradio UI with 3 tabs
โ”œโ”€โ”€ detector.py         # YOLO, OCR, vehicle classification
โ”œโ”€โ”€ database.py         # SQL validation, LLM, database operations
โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ””โ”€โ”€ .env               # Environment variables (Supabase, HF token)

Files Explained

app.py - Simplified UI layer

  • Detection tab: Upload images, detect plates
  • Database Query tab: NLP-to-SQL search with example queries
  • Analytics tab: Real-time dashboard with metrics

detector.py - Computer Vision Module

  • License plate detection using YOLO
  • OCR using PaddleOCR
  • Vehicle classification (10 types)
  • State code extraction (TN, KA, KL, etc.)
  • Image preprocessing and augmentation

database.py - Data & Security Layer

  • SQL validation (blocks DELETE, UPDATE, INSERT, DROP)
  • SQLCoder LLM integration for NLP-to-SQL
  • Database initialization with improved schema
  • Automatic index creation for performance
  • Query history tracking
  • Analytics functions (suspicious vehicles, hourly traffic, etc.)

๐Ÿš€ Deployment

Environment Variables

Create .env file with:

DATABASE_URL=postgresql://user:password@host:5432/postgres
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Run Locally

pip install -r requirements.txt
python app.py

Visit: http://localhost:7860

Deploy on Hugging Face Spaces

  1. Push code to HF Spaces repository
  2. Add secrets in Settings:
    • DATABASE_URL - Supabase connection string
    • HF_TOKEN - Hugging Face API token

๐Ÿ›ก๏ธ Security Measures

SQL Validation

ALLOWED_KEYWORDS = ["SELECT", "FROM", "WHERE", "COUNT", ...]
BLOCKED_KEYWORDS = ["DROP", "DELETE", "UPDATE", "INSERT", ...]

# Only SELECT queries allowed
# Blocks all dangerous operations

Database Schema

CREATE TABLE vehicle_logs (
    id BIGSERIAL PRIMARY KEY,
    timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    plate TEXT,
    state TEXT,
    vehicle_type TEXT,
    vehicle_conf FLOAT,
    camera_id TEXT,
    location TEXT,
    image_url TEXT,
    date DATE,
    hour INTEGER,
    day TEXT
);

Indexes for Performance

CREATE INDEX idx_plate ON vehicle_logs(plate);
CREATE INDEX idx_state ON vehicle_logs(state);
CREATE INDEX idx_vehicle_type ON vehicle_logs(vehicle_type);
CREATE INDEX idx_timestamp ON vehicle_logs(timestamp);
CREATE INDEX idx_date ON vehicle_logs(date);

๐ŸŽฏ Example Queries

  • "How many cars today?"
  • "Show all trucks"
  • "Count bikes"
  • "Show TN vehicles"
  • "Show vehicles after 6pm"
  • "List latest 10 detections"
  • "Count vehicles by type"
  • "Show high confidence detections"
  • "List all unique plates"
  • "Show suspicious vehicles"

๐Ÿ“Š Analytics Dashboard

  • Vehicles by State - Distribution of detections across states
  • Traffic by Hour - Hourly traffic patterns
  • Top Plates - Most frequently detected license plates
  • Suspicious Vehicles - High-frequency detections (>20 times)

๐Ÿ”ฎ Future Improvements

  • Vector search for similar plates
  • Async database queries for better performance
  • Image storage and retrieval
  • Camera tracking and geolocation
  • Result caching with Redis
  • FastAPI backend separation
  • React dashboard frontend

๐Ÿ“ฆ Dependencies

  • ultralytics - YOLO detection
  • paddleocr - OCR
  • transformers - Vehicle classification
  • sqlalchemy - Database ORM
  • huggingface-hub - LLM inference
  • gradio - Web UI
  • opencv - Image processing

๐Ÿ“„ License

MIT License - See LICENSE file

๐Ÿค Contributing

Contributions welcome! Please submit pull requests or issues.


Live Demo: https://huggingface.co/spaces/BARATH0070/plate-detector