GitHunt
SE

SeekAI-786/Pak_Constitution_chatbot

An AI-powered chatbot that answers questions about the Constitution of Pakistan using RAG (Retrieval Augmented Generation) with Pinecone vector database and Google Gemini.

Pakistan Constitution AI Chatbot

An AI-powered chatbot that answers questions about the Constitution of Pakistan using RAG (Retrieval Augmented Generation) with Pinecone vector database and Google Gemini.

Pakistan Constitution Bot

๐Ÿ—๏ธ Project Structure

pak_constitution/
โ”œโ”€โ”€ backend/           # FastAPI backend
โ”‚   โ”œโ”€โ”€ backend.py     # Main API server
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ””โ”€โ”€ .env.example   # Environment variables template
โ”œโ”€โ”€ frontend/          # Next.js frontend
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx       # Main chat page
โ”‚   โ”‚   โ”œโ”€โ”€ contact/       # Contact page
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx
โ”‚   โ”‚   โ””โ”€โ”€ globals.css
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ ...config files
โ””โ”€โ”€ README.md

๐Ÿš€ Features

  • RAG-based Q&A: Uses Pinecone for semantic search and Gemini for answer generation
  • ChatGPT-style UI: Clean, modern interface with sidebar navigation
  • Responsive Design: Works on desktop and mobile
  • Pakistan Theme: Green color scheme inspired by Pakistan's flag

๐Ÿ› ๏ธ Setup

Backend (FastAPI)

  1. Navigate to backend folder:

    cd backend
  2. Create virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Create .env file from example:

    cp .env.example .env
  5. Add your API keys to .env:

    PINECONE_API_KEY=your_pinecone_api_key
    GEMINI_API_KEY=your_gemini_api_key
    
  6. Run the server:

    uvicorn backend:app --reload

Backend will be available at http://localhost:8000

Frontend (Next.js)

  1. Navigate to frontend folder:

    cd frontend
  2. Install dependencies:

    npm install
  3. Create .env.local file:

    NEXT_PUBLIC_API_URL=http://localhost:8000
    
  4. Run development server:

    npm run dev

Frontend will be available at http://localhost:3000

๐ŸŒ Deployment

Backend on Railway

  1. Push to GitHub
  2. Connect Railway to your GitHub repo
  3. Add environment variables in Railway dashboard
  4. Deploy!

Frontend on Vercel

  1. Push to GitHub
  2. Import project in Vercel
  3. Set NEXT_PUBLIC_API_URL to your Railway backend URL
  4. Deploy!

๐Ÿ“ API Endpoints

  • POST /ask - Ask a question about the Constitution

    {
      "question": "What are the fundamental rights?"
    }
  • GET /health - Health check endpoint

๐Ÿ›ก๏ธ Tech Stack

  • Backend: FastAPI, Pinecone, Google Gemini
  • Frontend: Next.js 16, Tailwind CSS, TypeScript
  • Vector DB: Pinecone (llama-text-embed-v2)
  • LLM: Google Gemini 2.5 Flash

๐Ÿ‘จโ€๐Ÿ’ป Developed By

Echytech Solutions


Made with โค๏ธ for Pakistan