CoolFace
Apppublic

point9/BOQ_of_Tenders_Agent

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

BOQTenders - Bill of Quantities Extractor

A stateful agent system for extracting Bill of Quantities (BOQ) from tender documents and enabling document chat using LangGraph, LangChain, and Google Gemini LLM.

๐Ÿ—๏ธ Architecture

BOQTenders/
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ settings.py         # Pydantic settings with all configurable parameters
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ agent.py            # LangGraph-based agent for workflow orchestration
โ”‚   โ”œโ”€โ”€ pdf_extractor.py    # PDF text extraction via HuggingFace API
โ”‚   โ”œโ”€โ”€ embeddings.py       # Text chunking and FAISS vector store
โ”‚   โ”œโ”€โ”€ llm.py              # Google Gemini LLM client wrapper
โ”‚   โ””โ”€โ”€ rag_chain.py        # RAG chain builder for document Q&A
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ boq_extractor.py    # BOQ extraction service with iterative consistency
โ”‚   โ”œโ”€โ”€ consistency.py      # Consistency checking service
โ”‚   โ”œโ”€โ”€ mongo_store.py      # MongoDB event logging
โ”‚   โ””โ”€โ”€ s3_utils.py         # AWS S3 file storage
โ”œโ”€โ”€ api/
โ”‚   โ”œโ”€โ”€ routes.py           # FastAPI routes for /get_boq and /chat
โ”‚   โ””โ”€โ”€ schemas.py          # Pydantic request/response models
โ”œโ”€โ”€ prompts/
โ”‚   โ”œโ”€โ”€ get_prompts.py      # Prompt loader
โ”‚   โ””โ”€โ”€ templates.yaml      # LLM prompt templates
โ”œโ”€โ”€ app.py                  # FastAPI entry point
โ”œโ”€โ”€ streamlit_app.py        # Streamlit UI entry point
โ”œโ”€โ”€ Dockerfile              # Docker configuration
โ”œโ”€โ”€ docker-compose.yml      # Docker Compose configuration
โ””โ”€โ”€ requirements.txt        # Python dependencies

โœจ Features

  • โ€”๐Ÿ“„ PDF Processing: Extract text from tender documents using HuggingFace API
  • โ€”๐Ÿ” BOQ Extraction: Automatically identify and extract BOQ items with:
  • โ€”Item codes, descriptions, units, quantities
  • โ€”Unit prices, total amounts
  • โ€”Confidence scores for each item
  • โ€”Source page references
  • โ€”๐Ÿ”„ Consistency Checking: Iterative extraction with multiple runs for accuracy
  • โ€”๐Ÿ’ฌ Document Chat: Ask questions about processed documents using RAG
  • โ€”๐Ÿ—‚๏ธ Stateful Agent: LangGraph workflow for one-time extraction + multiple chats
  • โ€”๐Ÿ“Š Logging & Storage: MongoDB event logging and S3 file storage
  • โ€”๐ŸŒ Web UI: Streamlit interface for easy document upload and interaction
  • โ€”๐Ÿš€ API: FastAPI backend for programmatic access

Observability App โ†’ OpenTelemetry โ†’ OTEL Collector โ†’ (Tempo, Prometheus, Loki) โ†’ Grafana dashboards

Frontend Integration Use iframe embedding to show Grafana dashboards directly in your UI. See monitoring_api.py for iframe code generation.

๐Ÿš€ Quick Start

Prerequisites

  • โ€”Python 3.8+
  • โ€”Google Gemini API key
  • โ€”MongoDB (optional, for logging)
  • โ€”AWS S3 (optional, for file storage)

Installation

  1. 1.Clone the repository:
bash
   git clone <repository-url>
   cd BOQTenders
  1. 1.Create virtual environment:
bash
   python -m venv .venv
   source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. 1.Install dependencies:
bash
   pip install -r requirements.txt
  1. 1.Set up environment variables in .env:
env
   GOOGLE_API_KEY=your_gemini_api_key
   HF_API_TOKEN=your_huggingface_token
   LOG_LEVEL=DEBUG
   # Optional: MongoDB and S3 configs

Usage

Streamlit UI
bash
streamlit run streamlit_app.py
  • โ€”Upload PDF, enter API key, process document for BOQ extraction.
  • โ€”Chat with the document using the same API key.
FastAPI Backend
bash
uvicorn app:app --reload
API Endpoints
  • โ€”POST /get_boq: Extract BOQ from uploaded PDF
  • โ€”POST /chat: Chat with processed document

๐Ÿ“š API Documentation

Extract BOQ

bash
curl -X POST "http://localhost:8000/get_boq" \
     -H "Content-Type: application/json" \
     -d '{
       "file": "base64_encoded_pdf",
       "api_key": "your_api_key",
       "runs": 2,
       "boq_mode": ["default"]
     }'

Chat with Document

bash
curl -X POST "http://localhost:8000/chat" \
     -H "Content-Type: application/json" \
     -d '{
       "process_id": "session_id",
       "question": "What is the total quantity?",
       "api_key": "your_api_key"
     }'

๐Ÿ› ๏ธ Development

Project Structure

  • โ€”core/agent.py: Main LangGraph agent with simplified workflow
  • โ€”api/routes.py: FastAPI endpoints using agent
  • โ€”streamlit_app.py: Web UI with session management
  • โ€”services/: Business logic for extraction, consistency, storage

Key Components

  • โ€”Agent Workflow: Linear extraction graph + direct chat calls
  • โ€”State Management: AgentState TypedDict for workflow state
  • โ€”Error Handling: Graceful failures with logging

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make changes with tests
  4. 4.Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.