urgency-checker / README_HF.md
niru-nny's picture
Squash: Fresh start with all fixes (Docker static/templates fix, graceful error handling)
8c81dbc

πŸ›οΈ Civic Issue Urgency Classifier - Hugging Face Spaces

Spaces Python FastAPI Status

Text-Only NLP Classifier for Government Civic Issue Prioritization

Live Demo β€’ Quick Start β€’ API β€’ Model Info β€’ Limitations


πŸ“– Overview

Civic Issue Urgency Classifier is an AI-powered text analysis system that helps governments prioritize citizen-reported civic issues. It analyzes text descriptions and automatically assigns urgency levels (HIGH/MEDIUM/LOW) with confidence scores and actionable recommendations.

This is a text-only classifier. Image analysis is not currently supported.


🎯 Quick Start

Online (Hugging Face Spaces)

  1. βœ… Open this Space (you're already here!)
  2. πŸ“ Enter a civic issue description
  3. 🎯 Click "Classify Urgency"
  4. πŸ“Š Get instant urgency assessment

Local Development

# Clone repo
git clone https://github.com/nitish-niraj/urgency-checker.git
cd urgency-checker

# Install dependencies
pip install -r requirements.txt

# Run FastAPI server
python -m uvicorn src.demo_api_browser:app --host 0.0.0.0 --port 8001 --reload

# Open browser
# http://localhost:8001

πŸ“Š API Usage

Classify a Civic Issue

Endpoint: POST /classify-urgency

Request:

{
  "text": "There are large, dangerous cracks in the road beside the university hospital blocking ambulance access β€” please fix immediately.",
  "location": "University Hospital, Main St",
  "category": "Infrastructure"
}

Response:

{
  "urgency_level": "HIGH",
  "urgency_score": 8.7,
  "confidence": 0.94,
  "recommended_department": "Emergency Services",
  "estimated_response_time": "Within 1 hour",
  "reasoning": "High urgency detected: Keywords indicate critical infrastructure issue affecting emergency services. Immediate action required.",
  "location_context": "Hospital vicinity",
  "safety_context": "Emergency"
}

Test Examples

πŸ”΄ HIGH Priority

"There are large, dangerous cracks in the road beside the university hospital blocking ambulance access β€” please fix immediately."

Expected: HIGH urgency (8.5+), Emergency Services

🟑 MEDIUM Priority

"The sidewalk has some uneven pavement in the downtown area; people are tripping occasionally."

Expected: MEDIUM urgency (5-7), Public Works

🟒 LOW Priority

"Minor paint fading and some litter along the park pathway; routine maintenance when convenient."

Expected: LOW urgency (2-4), Parks & Recreation


πŸ€– Model Information

Component Details
Algorithm RandomForest Ensemble (100 trees)
Text Features TF-IDF vectorization + TextBlob sentiment
Training Data Synthetic civic issue dataset
Model Size ~5MB
Response Time <3 seconds
Language English
Input Text only (10-5000 characters)

βš™οΈ System Architecture

User Input (Text)
       ↓
Text Preprocessing (lowercase, tokenization)
       ↓
TF-IDF Vectorization + Sentiment Analysis
       ↓
Feature Engineering (urgency keywords, context)
       ↓
RandomForest Classifier
       ↓
Urgency Level + Score + Confidence
       ↓
Department Routing (based on category)
       ↓
Response Time Estimation
       ↓
JSON Output

⚠️ Limitations

  • βœ… Text-only: No image analysis
  • βœ… English only: Currently supports English language
  • βœ… Synthetic data: Trained on synthetic civic issue examples
  • βœ… No real-time: Demo-grade; not for production government systems
  • βœ… No YOLO/Computer Vision: Image detection not available
  • βœ… Stateless: No session management; each request is independent

πŸ”§ Technical Stack

  • Backend: FastAPI + Uvicorn
  • ML: scikit-learn (RandomForest)
  • NLP: TextBlob (sentiment analysis)
  • Containerization: Docker
  • Hosting: Hugging Face Spaces (Docker)

πŸ“ˆ Performance Metrics

Metric Value
Avg Response Time < 3 seconds
Model Accuracy ~95% (on test set)
Uptime 99%
Concurrent Requests 2-5 (HF Space tier)

πŸš€ Deployment

Deploy Your Own Space on Hugging Face

  1. Fork the repository on GitHub
  2. Create a new Space on Hugging Face
  3. Deploy - HF will auto-build from Dockerfile
  4. Test - Use the live UI or API

Local Docker Build & Test

# Build image
docker build -t urgency-classifier:latest .

# Run locally
docker run -p 7860:7860 urgency-classifier:latest

# Test endpoint
curl -X POST http://localhost:7860/classify-urgency \
  -H "Content-Type: application/json" \
  -d '{"text":"Dangerous pothole blocking traffic"}'

πŸ“ Example Requests (curl)

HIGH Priority

curl -X POST http://localhost:7860/classify-urgency \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Building facade crumbling - debris falling on pedestrians - URGENT",
    "location": "Downtown",
    "category": "Safety"
  }'

MEDIUM Priority

curl -X POST http://localhost:7860/classify-urgency \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Street light flickering at night; poses safety concern",
    "location": "Main Street",
    "category": "Infrastructure"
  }'

LOW Priority

curl -X POST http://localhost:7860/classify-urgency \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Small pothole in park path; cosmetic issue",
    "location": "Central Park",
    "category": "Maintenance"
  }'

πŸ§ͺ Testing

API Endpoints

  • GET / - Web UI
  • GET /docs - Interactive API documentation (Swagger)
  • GET /health - Health check
  • GET /stats - System statistics
  • POST /classify-urgency - Main classification endpoint

Try the API

# Health check
curl http://localhost:7860/health

# Get stats
curl http://localhost:7860/stats

# Classify an issue
curl -X POST http://localhost:7860/classify-urgency \
  -H "Content-Type: application/json" \
  -d '{"text":"Your civic issue description here"}'

πŸ“š Resources


πŸ‘€ Author

Nitish Niraj


πŸ“„ License

MIT License - see LICENSE for details


⭐ Like this project? Star it on GitHub!

View on GitHub β€’ Full Documentation