An AI-powered system for recommending road safety interventions based on IRC standards, using Google Gemini API and hybrid RAG search.
- Multi-Interface Support: Web App (Streamlit), REST API (FastAPI), and CLI Tool
- Hybrid Search: Combines RAG (vector similarity) and structured queries
- AI-Powered: Google Gemini for embeddings, entity extraction, and synthesis
- Comprehensive Database: 105+ road safety interventions from IRC standards
- Smart Recommendations: Confidence scoring, detailed specifications, and IRC citations
π¨ Visual Generation
- Auto-generate road sign images from IRC specifications
- Create road marking diagrams (arrows, zebra crossings, chevrons, etc.)
- Instant visual previews with accurate colors and dimensions
π PDF Report Generation
- Professional, multi-page PDF reports with branding
- Executive summaries and detailed specifications
- Download-ready reports for stakeholders
πΈ Image Analysis with AI
- Upload photos of road signs/markings for instant analysis
- Automatic identification and condition assessment
- Auto-generate search queries from images
- Gemini Vision-powered recognition
π Multi-Intervention Planning
- Create comprehensive implementation plans
- Timeline generation with start/end dates
- Cost aggregation and budget tracking
- Priority-based optimization
βοΈ Budget Optimization
- Maximize safety impact within budget constraints
- Value/cost ratio analysis
- Smart intervention selection algorithm
π Interactive Comparison
- Compare interventions side-by-side
- Multi-factor winner analysis
- Trade-off identification
π Analytics Dashboard
- Comprehensive statistics and insights
- Category and problem distributions
- Search history analytics
- Actionable recommendations
π See WOW_FEATURES.md for detailed documentation!
βββββββββββββββββββββββββββββββββββββββββββ
β User Interfaces β
β - Streamlit Web App (Streamlit Cloud) β
β - REST API (Railway) β
β - CLI Tool β
βββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Backend Core (FastAPI + Python) β
β - Query Orchestrator β
β - Multi-Strategy Search β
β β’ RAG (Vector Similarity) β
β β’ Structured Queries β
β β’ Hybrid Fusion (RRF) β
β - Gemini Service β
βββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Data Layer β
β - ChromaDB (Vector Store) β
β - SQLite/JSON (Structured Data) β
β - Cache (In-Memory TTL) β
βββββββββββββββββββββββββββββββββββββββββββ
- Python 3.11+
- Google Gemini API Key (Get it here)
- Git
git clone <repository-url>
cd Road-Safety-Intervention-Chatbot# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install backend dependencies
cd backend
pip install -r requirements.txt
cd ..# Copy example env file
cp .env.example .env
# Edit .env and add your Gemini API key
# GEMINI_API_KEY=your_gemini_api_key_here
# API_KEYS=key1,key2,key3 # Generate random keys for API accesspython backend/scripts/setup_database.pyThis will:
- Clean and enrich the CSV data
- Generate embeddings using Gemini
- Create vector store (ChromaDB)
- Save processed data as JSON
cd backend
uvicorn app.main:app --reloadAPI will be available at: http://localhost:8000 API Docs: http://localhost:8000/docs
cd frontend
pip install -r requirements.txt
# Copy frontend env
cp .env.example .env
# Edit and add API_URL and API_KEY
streamlit run app.pyFrontend will be available at: http://localhost:8501
cd cli
pip install -e .
# Configure CLI
road-safety config set api_url http://localhost:8000
road-safety config set api_key your_api_key_here
# Test CLI
road-safety search query "faded stop sign on highway"- Open http://localhost:8501
- Enter your road safety query in natural language
- Apply filters (optional)
- View ranked recommendations with AI analysis
Local Development:
curl -X POST "http://localhost:8000/api/v1/search" \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"query": "faded stop sign on highway",
"max_results": 5
}'Production (Deployed Backend):
curl -X POST "https://road-safety-intervention-chatbot-production.up.railway.app/api/v1/search" \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"query": "faded stop sign on highway",
"max_results": 5
}'# Direct search
road-safety search query "damaged speed breaker"
# Interactive mode
road-safety interactive start
# With filters
road-safety search query "faded marking" \
--category "Road Marking" \
--speed-min 50 \
--speed-max 100| Variable | Description | Default |
|---|---|---|
GEMINI_API_KEY |
Google Gemini API key | Required |
API_KEYS |
Comma-separated API keys | Required |
ENVIRONMENT |
Environment (development/production) | development |
LOG_LEVEL |
Logging level | info |
DEFAULT_SEARCH_STRATEGY |
Default search strategy | hybrid |
MAX_RESULTS |
Default max results | 5 |
# Set environment variables in .env file
cp .env.example .env
# Build and run
docker-compose up --build
# Access services:
# Backend: http://localhost:8000
# Frontend: http://localhost:8501Backend:
cd backend
docker build -t road-safety-backend .
docker run -p 8000:8000 \
-e GEMINI_API_KEY=your_key \
-e API_KEYS=key1,key2 \
-e ENVIRONMENT=production \
road-safety-backendFrontend:
cd frontend
docker build -t road-safety-frontend .
docker run -p 8501:8501 \
-e API_URL=http://localhost:8000 \
-e API_KEY=your_api_key \
road-safety-frontendNote: The backend Dockerfile uses a multi-stage build and automatically generates interventions.json from CSV on first startup if missing.
The backend is deployed and running on Railway:
π Backend URL: https://road-safety-intervention-chatbot-production.up.railway.app
Deployment Steps:
- Push code to GitHub
- Create new project on Railway
- Connect GitHub repository
- Set build context to root (
.) - Set Dockerfile path to
backend/Dockerfile - Set environment variables in Railway:
GEMINI_API_KEY- Your Google Gemini API keyAPI_KEYS- Comma-separated API keys for authenticationENVIRONMENT=production
- Railway will auto-deploy on push
Configuration Files:
railway.json- Railway deployment configurationbackend/Dockerfile- Multi-stage Docker build.dockerignore- Excludes unnecessary files from build
Key Features:
- Auto-generates
interventions.jsonfrom CSV on first startup - Handles empty vector store gracefully (falls back to structured search)
- CORS enabled for frontend connections
Deployment Steps:
- Go to share.streamlit.io
- Sign in with your GitHub account
- Click "New app"
- Configure:
- Repository:
N1KH1LT0X1N/Road-Safety-Intervention-Chatbot - Branch:
main - Main file path:
frontend/app.py
- Repository:
- Click "Deploy!"
- After deployment, go to Settings β Secrets and add:
API_URL = "https://road-safety-intervention-chatbot-production.up.railway.app" API_KEY = "your-api-key-from-railway"
Alternative: Deploy Frontend on Railway
- Create a new Railway service
- Set root directory to
frontend/ - Use the
frontend/Dockerfile - Set environment variables:
API_URLandAPI_KEY
See DEPLOYMENT_STEPS.md for detailed deployment instructions.
Base URL: https://road-safety-intervention-chatbot-production.up.railway.app
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/stats |
GET | Database statistics |
/api/v1/search |
POST | Search interventions |
/api/v1/interventions |
GET | List interventions |
/api/v1/interventions/{id} |
GET | Get specific intervention |
/api/v1/interventions/categories/list |
GET | List categories |
/api/v1/interventions/problems/list |
GET | List problem types |
API Documentation: Visit https://road-safety-intervention-chatbot-production.up.railway.app/docs for interactive API docs.
Authentication: All API endpoints require an X-API-Key header with a valid API key.
# Run test queries
python backend/scripts/test_queries.py
# Run unit tests (if implemented)
cd backend
pytestRoad-Safety-Intervention-Chatbot/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ api/ # API routes
β β βββ core/ # Business logic
β β βββ models/ # Data models
β β βββ services/ # Services
β β βββ utils/ # Utilities
β βββ data/ # Data files
β β βββ raw/ # Raw CSV data
β β βββ processed/ # Processed JSON data
β β βββ chroma_db/ # Vector store
β βββ scripts/ # Setup scripts
β βββ Dockerfile # Docker configuration
β βββ requirements.txt # Python dependencies
βββ frontend/ # Streamlit web app
β βββ utils/ # Utilities (API client)
β βββ app.py # Main app
β βββ Dockerfile # Docker configuration
β βββ requirements.txt # Python dependencies
β βββ vercel.json # Vercel config (not used - use Streamlit Cloud)
βββ cli/ # CLI tool
β βββ road_safety_cli/ # CLI package
βββ docs/ # Documentation
βββ railway.json # Railway deployment config
βββ .dockerignore # Docker ignore rules
βββ DEPLOYMENT_STEPS.md # Deployment guide
βββ README.md # This file
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License.
- Google Gemini API for AI capabilities
- IRC Standards for road safety data
- FastAPI, Streamlit, and Typer frameworks
For questions or support, please open an issue on GitHub.
Built with β€οΈ for Road Safety