Skip to content

Latest commit

 

History

History
254 lines (181 loc) · 5.31 KB

File metadata and controls

254 lines (181 loc) · 5.31 KB

🎯 QueryGPT - START HERE

A powerful Natural Language to SQL platform powered by Google Gemini AI


⚡ Quick Start (3 Steps)

1️⃣ Get Your Gemini API Key (2 minutes)

  1. Visit: https://makersuite.google.com/app/apikey
  2. Sign in with Google
  3. Click "Create API Key"
  4. Copy the key

2️⃣ Set Up Your API Key (1 minute)

Create a .env file:

cp env_template.txt .env

Edit .env and paste your API key:

GEMINI_API_KEY=your_actual_api_key_here

3️⃣ Start the Server (1 minute)

Easy way:

chmod +x start_server.sh
./start_server.sh

Manual way:

pip3 install -r requirements.txt
python3 backend/app.py

Then open index.html in your browser!


📁 Project Structure

NLP/
├── 📄 START_HERE.md           ← You are here!
├── 📘 SETUP_GUIDE.md           ← Detailed setup & troubleshooting
├── 📘 README.md                ← Full documentation
│
├── 🌐 index.html               ← Frontend interface (open this!)
├── 🚀 start_server.sh          ← Easy startup script
│
├── backend/
│   ├── app.py                  ← Flask API server (Gemini integration)
│   ├── schema_context.txt      ← Database schema for AI
│   └── example_queries.txt     ← Example SQL patterns
│
├── 📋 requirements.txt         ← Python dependencies
├── 🔧 env_template.txt         ← Environment variables template
└── .gitignore                  ← Git ignore rules

🎮 How to Use

1. Type Your Query in Plain English

Examples:

  • "Show all farmers by partner"
  • "List kyaris created last month"
  • "Get farms with missing documents"
  • "Show species distribution by district"

2. Click "Generate & Execute Query"

The AI will:

  • ✅ Understand your request
  • ✅ Generate proper SQL
  • ✅ Execute it safely
  • ✅ Display beautiful results

3. Export or Analyze

  • 📊 View results in a table
  • 📥 Export as CSV or JSON
  • 📋 Copy the generated SQL
  • 🔄 Refine and re-run

🎯 What Makes This Special?

✨ Smart AI Understanding

  • Knows your complete database schema
  • Understands relationships between tables
  • Learns from example queries
  • Generates optimized SQL

🔒 Safety First

  • Read-only queries - No data modification possible
  • SQL validation - Blocks dangerous operations
  • Read-only user - Database-level protection
  • Input sanitization - SQL injection protection

🚀 Production Ready

  • Fast query execution
  • Beautiful, responsive UI
  • Error handling & validation
  • Performance metrics
  • Export functionality

💡 Example Queries You Can Try

📊 Documentation Reports

Show me documentation status by partner organization

🌱 Plantation Analytics

List all kyaris with species information created in the last 30 days

📍 Location-Based

Get all farmers in Punjab state with their farm details

📋 Missing Data

Find farms with missing land records grouped by district

🌳 Species Distribution

Show primary and secondary species distribution across all plantations

⏰ Time-Based Analysis

Get kyari creation trends by month for 2025

🔧 Configuration

Database

Already configured for your read-only replica:

  • Host: farmer-read-replica.crqfrvul5g3i.ap-south-1.rds.amazonaws.com
  • Database: production
  • User: readonly

API

  • Backend: http://localhost:5000
  • Frontend: Open index.html in browser
  • Model: Gemini 1.5 Pro

⚠️ Troubleshooting

"Gemini API key not configured"

→ Add your API key to .env file

"Connection Failed"

→ Check internet connection and database access

Port 5000 in use

→ Kill existing process: lsof -ti:5000 | xargs kill -9

Dependencies error

→ Run: pip3 install --upgrade -r requirements.txt

For more help, see SETUP_GUIDE.md


📊 What Data Can You Query?

Core Data

  • ✅ Farmers & Farms
  • ✅ Kyaris (Plantation Plots)
  • ✅ Species & Plantation Models
  • ✅ Documentation Status

Location Data

  • ✅ Countries, States, Districts
  • ✅ Blocks & Villages
  • ✅ Geographic coordinates

Project Data

  • ✅ Biochar Production
  • ✅ AWD (Water Management)
  • ✅ Carbon Quantification
  • ✅ Survey Details

Analytics

  • ✅ Documentation compliance
  • ✅ Plantation progress
  • ✅ Species distribution
  • ✅ Partner performance

🎓 Tips for Best Results

  1. Be Specific: "Farmers in Punjab created last month" > "Show farmers"

  2. Use Filters: Include date ranges, partners, locations, statuses

  3. Check SQL: Review generated SQL to understand the query

  4. Iterate: Refine your query if results aren't perfect

  5. Use Examples: Click example cards to see patterns


🚀 Next Steps

  1. ✅ Start the server
  2. ✅ Open index.html
  3. ✅ Try an example query
  4. ✅ Explore your data!

📞 Support

  • Setup Issues: See SETUP_GUIDE.md
  • Usage Help: See README.md
  • Console Errors: Check browser DevTools (F12)
  • Server Errors: Check terminal output

🎉 You're All Set!

Your non-technical team can now query the database using plain English!

Just open index.html and start exploring your data. No SQL knowledge required! 🚀


Made with ❤️ using Google Gemini AI