An intelligent chatbot system for querying and analyzing groundwater data from India's Central Ground Water Board (CGWB). Built with FastAPI, React, and LangChain.
π Try it now: [Coming Soon - Deploy using DEPLOYMENT_GUIDE.md]
Backend API: [Your Render URL]
API Documentation: [Your Render URL]/docs
- Natural Language Queries: Ask questions in plain English about groundwater data
- Filter-Based Queries: Use structured filters for precise data retrieval
- Theme System: 4 beautiful themes (Light, Dark, Ocean, Forest)
- Data Visualization: Interactive charts and tables using Recharts
- SQL-Driven: Zero hallucination - all data comes from database queries
- Multi-Year Support: Query data across multiple years (2016-2025)
- District-Level Data: Access detailed district-level groundwater information
- Years: 2016-17, 2019-20, 2021-22, 2022-23, 2023-24, 2024-25
- States/UTs: 37 states and union territories
- Districts: ~700 districts across India
- Records: 4,160 clean, validated records
- Metrics: 154 columns including:
- Total Ground Water Availability
- Rainfall
- Ground Water Recharge
- Extraction Rates
- Environmental Flows
- And more...
- Python 3.10+
- Node.js 16+
- OpenAI API key
- Clone the repository
git clone <repository-url>
cd ingres-chatbot- Set up Python environment
python -m venv venv
source venv/Scripts/activate # Windows
source venv/bin/activate # Linux/Mac
pip install -r requirements.txt- Set up environment variables
# Create .env file
echo "OPENAI_API_KEY=your_api_key_here" > .env- Install frontend dependencies
cd frontend
npm install
cd ..- Start the backend server
# From project root
uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000- Start the frontend server (in a new terminal)
cd frontend
npm run dev- Access the application
- Frontend: http://localhost:5173
- Backend API: http://127.0.0.1:8000
- API Docs: http://127.0.0.1:8000/docs
ingres-chatbot/
βββ backend/
β βββ main.py # FastAPI application
β βββ chatbot_v2.py # LangChain chatbot with validation
β βββ query_handler.py # Direct SQL query handler
β βββ security.py # Input sanitization
βββ frontend/
β βββ src/
β β βββ App.jsx # Main React component
β β βββ themes.js # Theme system
β β βββ components/ # React components
β βββ index.html
β βββ package.json
βββ data/
β βββ raw_excel/ # Original Excel files from CGWB
βββ notebooks/
β βββ preprocess_groundwater_data.py # Data preprocessing
β βββ create_database.py # Database creation
β βββ update_database_with_cleaned_data.py
βββ processed_data/
β βββ groundwater_cleaned.csv # Cleaned dataset
β βββ preprocessing_report.txt # Validation report
βββ groundwater.db # SQLite database
βββ requirements.txt # Python dependencies
βββ package.json # Node.js dependencies
βββ README.md # This file
POST /chat
Content-Type: application/json
{
"question": "Which state has the highest groundwater availability?"
}POST /filter_query
Content-Type: application/json
{
"metric": "Total Ground Water Availability in the area (ham) Fresh",
"states": ["ASSAM"],
"years": ["2024_25"]
}"Which state has the highest groundwater availability?"
"What is the rainfall in Punjab for 2023-24?"
"Top 5 states by groundwater recharge"
"Show extraction rate in Rajasthan"
"Compare groundwater in Assam and Andhra Pradesh"
- Select a metric (e.g., "Total Ground Water Availability")
- Select state(s) (e.g., "Assam", "Punjab")
- Select year(s) (e.g., "2024-25")
- Click "Run Query"
Switch between 4 themes using the buttons in the header:
- βοΈ Light Mode: Clean white background (default)
- π Dark Mode: Dark slate background for low-light environments
- π Ocean Theme: Cyan/blue colors with water theme
- πΏ Forest Theme: Green/emerald tones with nature theme
Theme preference is saved in localStorage and persists across sessions.
The data preprocessing pipeline ensures 100% data integrity:
- Dynamic Header Detection: Automatically finds actual header row
- Multi-Level Headers: Handles C, NC, PQ, Total, Fresh, Saline categories
- Metadata Removal: Removes report metadata rows
- Duplicate Detection: Identifies and removes duplicates
- Column Standardization: Cleans and standardizes column names
- Data Type Conversion: Converts numeric columns properly
- Validation: Comprehensive validation and anomaly detection
Run preprocessing:
python notebooks/preprocess_groundwater_data.pyUpdate database:
python notebooks/update_database_with_cleaned_data.py- All responses come from SQL queries
- Strict validation rejects any generated numbers
- No approximations or estimates
- Rainfall: Uses AVG() (intensity measure)
- Availability: Uses SUM() for state totals (STOCK variable)
- Recharge: Uses SUM() (FLOW variable)
- Extraction Rate: Uses AVG() (percentage)
- Single year: Returns specific year data
- Multiple years: Returns year-wise breakdown
- Proper handling of STOCK vs FLOW variables
- Direct SQL handler for common queries (<1 second)
- LLM fallback for complex queries (5-10 seconds)
- No timeout errors
- Update
COLUMN_MAPinbackend/query_handler.py - Add aggregation rule in
AGG_RULES - Add unit in
UNITS - Update
valid_metricsinbackend/main.py - Update
METRICSarray infrontend/src/App.jsx
# Test preprocessing
python notebooks/preprocess_groundwater_data.py
# Test database
python notebooks/create_database.py
# Test API
curl -X POST http://127.0.0.1:8000/chat \
-H "Content-Type: application/json" \
-d '{"question": "Which state has highest groundwater?"}'Data sourced from:
- Central Ground Water Board (CGWB)
- Ministry of Jal Shakti, Government of India
- Dynamic Groundwater Resources Reports (2016-2025)
- NEVER generate synthetic data
- NEVER fill missing values with assumptions
- ONLY use real values from Excel files
- Preserve original data integrity at all costs
- STOCK variables (Availability): Use latest year, don't sum across years
- FLOW variables (Recharge): Can sum across years
- Rainfall: Always use AVG(), never SUM()
- Percentages: Always use AVG(), never SUM()
# Check if port 8000 is in use
netstat -ano | findstr :8000 # Windows
lsof -i :8000 # Linux/Mac
# Restart backend
uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000# Clear cache and reinstall
cd frontend
rm -rf node_modules package-lock.json
npm install
npm run dev# Restore from backup
cp groundwater_backup.db groundwater.db
# Or regenerate from cleaned data
python notebooks/update_database_with_cleaned_data.pyThis project is developed for the Central Ground Water Board (CGWB), Ministry of Jal Shakti, Government of India.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For questions or support, please contact the development team.
Ready to deploy? Follow our comprehensive guides:
- DEPLOYMENT_GUIDE.md - Step-by-step deployment instructions
- DEPLOYMENT_CHECKLIST.md - Quick checklist for deployment
Backend (Render):
Build: pip install -r requirements.txt
Start: uvicorn backend.main:app --host 0.0.0.0 --port 10000Frontend (Vercel):
Root: frontend
Framework: Vite
Env: VITE_API_URL=https://your-backend-url.onrender.comBuilt with β€οΈ for sustainable groundwater management in India