Skip to content

๐Ÿ—๏ธ AI construction intelligence platform: ๐Ÿ’ฌ RAG-powered Q&A, ๐ŸŽš๏ธ what-if simulations, ๐Ÿ“Š explainable insights, ๐Ÿ“„ smart document analysis. FastAPI + React + LangChain + OpenAI/Gemini โšก

Notifications You must be signed in to change notification settings

sparshagra/WhatIF_Chatbot-AI_powered_document_analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ— What-If RAG: Explainable Construction Project Intelligence

FastAPI React TypeScript LangChain OpenAI Google Gemini License

An AI-powered construction project management platform that provides explainable insights, scenario simulations, and intelligent document analysis through an intuitive chat-based experience.

Built by The Multiverse Task Force โ€” Sparsh Agarwal & Divy Dobariya

โ–ถ๏ธ Demo Video

Watch the video


๐ŸŽฏ Problem Statement

This project addresses two critical challenges in construction and capital planning:

Challenge 1: What-If Analysis with Explainable AI:

  • Existing tools cannot simulate project changes in real-time or show impact instantly
  • No transparency on why decisions are suggested, making planning slow and unclear

Challenge 2: NLP-based Contract Analysis:

  • Key contract details are buried in documents, causing delays and missed risks
  • No smart search or automated compliance alerts โ€” review is manual and error-prone

Construction projects suffer from:

  • Scattered Data: Critical information buried across PDFs, contracts, BIM models, and reports
  • Manual Review Bottlenecks: Hours spent searching for clauses, deadlines, and compliance requirements
  • Opaque Dashboards: No understanding of why metrics are flagged or how scores are calculated
  • Slow Decision-Making: Unable to quickly simulate "what-if" scenarios for cost overruns or timeline delays

โœจ Solution: Unified AI-Powered Platform

Core Capabilities

๐Ÿ” RAG-Based Document Intelligence โ€” Natural language queries on project documents with source citations

๐ŸŽš๏ธ Interactive What-If Simulator โ€” Real-time scenario testing with explainable impact analysis using tunable sliders

๐Ÿ“Š Visual Insights Dashboard โ€” Highlights, risks, and document chat with transparent reasoning

๐Ÿ” Explainable AI โ€” Every insight includes reasoning chains and audit trails

๐Ÿค– Dual AI Backend โ€” Choose between OpenAI GPT-4 (production) or Google Gemini (free tier)


๐Ÿš€ Quick Start

Prerequisites


๐Ÿ”ง Step 1: Backend Setup

Choose Your AI Provider

Option A: OpenAI Backend (Recommended for production)

# Navigate to backend
cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env and add: OPENAI_API_KEY=sk-your_key_here

# Start server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Option B: Google Gemini Backend (Free alternative)

# Navigate to Gemini version
cd backend/gemini_version

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env and add: GOOGLE_API_KEY=your_gemini_key_here

# Start server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

โœ… Backend running at: http://localhost:8000
๐Ÿ“š API Docs: http://localhost:8000/docs


๐ŸŽจ Step 2: Frontend Setup

# Open new terminal and navigate to frontend
cd frontend

# Install dependencies
npm install

# Configure backend connection
cp .env.example .env
# Edit .env and add: VITE_API_BASE_URL=http://localhost:8000

# Start development server
npm run dev

โœ… Frontend running at: http://localhost:5173


๐Ÿ“ Project Structure

whatif-rag-construction/
โ”‚
โ”œโ”€โ”€ backend/                        # OpenAI-powered backend
โ”‚   โ”œโ”€โ”€ loader.py                   # Multi-format document ingestion
โ”‚   โ”œโ”€โ”€ vectorstore.py              # ChromaDB + OpenAI embeddings
โ”‚   โ”œโ”€โ”€ rag_chain.py                # AI reasoning engine
โ”‚   โ”œโ”€โ”€ main.py                     # FastAPI server
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ backend/gemini_version/         # Google Gemini backend (free)
โ”‚   โ”œโ”€โ”€ loader.py
โ”‚   โ”œโ”€โ”€ vectorstore.py              # ChromaDB + Gemini embeddings
โ”‚   โ”œโ”€โ”€ rag_chain.py
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ””โ”€โ”€ frontend/                       # React + TypeScript UI
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ components/             # Reusable UI components
    โ”‚   โ”œโ”€โ”€ pages/                  # Main application views
    โ”‚   โ”‚   โ”œโ”€โ”€ Welcome.tsx
    โ”‚   โ”‚   โ”œโ”€โ”€ Chat.tsx
    โ”‚   โ”‚   โ”œโ”€โ”€ ScenarioTuning.tsx
    โ”‚   โ”‚   โ””โ”€โ”€ VisualInsights.tsx
    โ”‚   โ”œโ”€โ”€ contexts/               # Global state management
    โ”‚   โ””โ”€โ”€ App.tsx
    โ””โ”€โ”€ package.json

๐Ÿ— Architecture & Workflow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Upload Documentsโ”‚  โ† PDF, DOCX, BIM, CSV, Images
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Document Loaderโ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ Vector Store โ”‚  โ† ChromaDB
โ”‚  (Chunking)     โ”‚      โ”‚  (Embeddings)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚                       โ”‚                    โ”‚
         โ–ผ                       โ–ผ                    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  RAG Chat       โ”‚   โ”‚  Dashboard AI   โ”‚   โ”‚  What-If Engine โ”‚
โ”‚  Q&A + Citationsโ”‚   โ”‚  Health Scoring โ”‚   โ”‚  Scenario Tuningโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                    โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚  React Frontend โ”‚
                       โ”‚  Chat Interface โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ›  Technology Stack

Backend

  • AI Models: OpenAI GPT-4/GPT-4o | Google Gemini Pro
  • RAG Framework: LangChain 0.3.14
  • Vector Database: ChromaDB 0.5.23
  • API Framework: FastAPI 0.120.3
  • Document Processing: PyPDF, python-docx, ezdxf, IfcOpenShell, Pandas

Frontend

  • Framework: React 18+ with TypeScript
  • Build Tool: Vite
  • Routing: React Router
  • State Management: Context API
  • Styling: Tailwind CSS (via UI components)

๐ŸŽฎ Key Features

1. RAG-Powered Chat Interface

  • Ask natural language questions about uploaded documents
  • Get instant answers with source citations
  • Conversational follow-ups maintain context
  • Example: "What is the payment schedule?" โ†’ Returns answer with contract section reference

2. Interactive Scenario Tuning

  • 5 Adjustable Sliders (scored 1-5):
    • Cost Management
    • Timeline Adherence
    • Design Quality
    • Regulatory Compliance
    • Sustainability
  • Real-time Analysis: View strengths, weaknesses, and top 3 recommended changes
  • What-If Simulation: See instant impact of parameter adjustments
  • Example: "What if I reduce timeline score from 4 to 2?" โ†’ Shows impact + mitigation steps

3. Visual Insights Dashboard

  • Highlights: Key achievements and positive indicators
  • Risks: Identified threats requiring attention
  • Document Chat: Ask specific questions with contextual answers
  • Example: "Which clauses address force majeure events?" โ†’ Extracts and cites relevant sections

4. Explainable AI

  • Every response includes reasoning chain
  • Source citations for all claims
  • Audit trails for compliance and transparency

๐Ÿ“‚ Supported File Formats

Format Use Case Processing
PDF Contracts, reports Page-based chunking
DOCX Proposals, change orders Text extraction
CSV/XLSX Cost sheets, schedules Table summarization
IFC/BIM 3D building models Entity extraction
DWG/DXF CAD drawings Layer analysis
Images Site photos, diagrams Tesseract OCR

๐Ÿ”ง API Endpoints

Endpoint Method Description
/upload POST Upload and index documents
/search POST Ask questions (RAG Q&A)
/dashboard GET Get AI project health scores
/highlights GET Extract key terms and risks
/ask POST Run what-if scenario simulations

Example: Ask Question

curl -X POST "http://localhost:8000/search" \
  -H "Content-Type: application/json" \
  -d '{"question": "What are the liquidated damages?"}'

๐Ÿงช Example Workflow

  1. Upload Project Documents (via UI)

    • Contract PDF
    • Cost estimate XLSX
    • Structural plans PDF
  2. View Dashboard โ†’ Get overall health score with AI reasoning

  3. Extract Insights โ†’ Automated highlights of deadlines, risks, compliance gaps

  4. Run Scenario โ†’ "What if steel delivery is delayed 4 weeks?" โ†’ Impact analysis + 3-step mitigation

  5. Ask Questions โ†’ "What are the payment milestones?" โ†’ Answer with section citations


๐Ÿš€ Production Deployment

Backend

# Build for production
pip install -r requirements.txt

# Run with Gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000

Frontend

# Build production bundle
npm run build

# Preview locally
npm run preview

# Deploy dist/ folder to hosting service (Vercel, Netlify, AWS S3)

๐Ÿ› Troubleshooting

Backend won't start:

  • Verify Python 3.10+: python --version
  • Check API key in .env
  • Ensure dependencies: pip install -r requirements.txt

Frontend can't connect:

  • Verify backend running: curl http://localhost:8000/about
  • Check VITE_API_BASE_URL in frontend .env
  • Ensure CORS enabled in backend main.py

Vector search fails:

  • Clear ChromaDB: rm -rf /tmp/chroma_store
  • Check write permissions

๐Ÿค Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/AmazingFeature
  3. Commit changes: git commit -m 'Add AmazingFeature'
  4. Push to branch: git push origin feature/AmazingFeature
  5. Open Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


๐Ÿ‘ฅ Team

The Multiverse Task Force

  • Sparsh Agarwal โ€” Front End and System Integration
  • Divy Dobariya โ€” Backend Development & AI/ML, Langchain, RAG Architechture

Built for Aurigo Hackathon 2025 ๐Ÿš€


๐Ÿ“ž Support


โšก Make better construction decisions, faster, with transparent AI reasoning.

โญ Star this repo if you find it useful!

About

๐Ÿ—๏ธ AI construction intelligence platform: ๐Ÿ’ฌ RAG-powered Q&A, ๐ŸŽš๏ธ what-if simulations, ๐Ÿ“Š explainable insights, ๐Ÿ“„ smart document analysis. FastAPI + React + LangChain + OpenAI/Gemini โšก

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •