CoolFace
Apppublic

dineshupadhya/docqa-chatbot

sourceHugging Faceupdated 11d agoView on Hugging Face
0likes
App README

DocQA Chatbot v3.0

A full-stack Document Q&A Chatbot powered by RAG (Retrieval-Augmented Generation). Upload documents, ask questions via text or voice, compare documents, visualize similarity scores, and get AI-powered answers with highlighted source citations.

Built by: Dinesh Raj Upadhya

Live Demo

[dineshupadhya-docqa-chatbot.hf.space](https://dineshupadhya-docqa-chatbot.hf.space)


Features

Core

  • —RAG Pipeline — Retrieves relevant document chunks before answering, ensuring grounded responses
  • —Multi-Model Support — Choose between Flan-T5 (free, fast) or GPT-3.5 Turbo (best quality)
  • —Batch Upload — Upload multiple PDF, DOCX, TXT, CSV, MD files at once
  • —Streaming Answers — Watch answers appear word-by-word with cursor animation

Voice

  • —Voice Input — Record audio questions via browser microphone (Google Speech Recognition)
  • —Voice Output — Listen to AI answers with text-to-speech (gTTS)
  • —Query Suggestions — Auto-generated clickable questions after document upload

Analysis

  • —Document Comparison — Side-by-side AI comparison of two documents with word overlap stats
  • —Vector Similarity Visualization — Interactive Plotly bar chart showing chunk relevance scores
  • —Highlighted Sources — Source text highlights keywords from your question in bold
  • —Document Analytics — Word count, sentence count, top words with interactive charts
  • —Chunk Viewer — Browse and filter all indexed text chunks

Utility

  • —URL Scraper — Scrape any webpage and ask questions about its content
  • —Chat Persistence — Save/load/delete conversations via SQLite sessions
  • —Export Chat — Download conversation history as a formatted text file
  • —Auto-Summarize — Generate one-click summaries of uploaded documents
  • —OpenAI Integration — Optional API key input to use GPT-3.5 Turbo

How It Works

User uploads document
        │
        ▼
┌──────────────────┐
│  Document Loader  │  ← PDF / TXT / DOCX / CSV / MD
└────────┬─────────┘
         ▼
┌──────────────────┐
│  Text Splitter    │  ← RecursiveCharacterTextSplitter (500 chars, 50 overlap)
└────────┬─────────┘
         ▼
┌──────────────────┐
│  Embeddings       │  ← HuggingFace all-MiniLM-L6-v2 (384-dim vectors)
└────────┬─────────┘
         ▼
┌──────────────────┐
│  ChromaDB         │  ← Persistent vector store on disk
└────────┬─────────┘
         ▼
User asks a question
         │
         ▼
┌──────────────────┐
│  Retriever        │  ← Cosine similarity, top 5 chunks
└────────┬─────────┘
         ▼
┌──────────────────┐
│  LLM              │  ← Flan-T5-small or GPT-3.5 Turbo
└────────┬─────────┘
         ▼
    Answer with sources

Tech Stack

LayerTechnology
FrontendStreamlit, Plotly, gTTS
BackendFastAPI, Uvicorn
RAGLangChain, ChromaDB
EmbeddingsHuggingFace all-MiniLM-L6-v2
LLMFlan-T5-small (free) / GPT-3.5 Turbo
Voice InputSpeechRecognition + Google Web Speech API
Voice OutputgTTS (Google Text-to-Speech)
DatabaseSQLite (chat sessions)
DeploymentHuggingFace Spaces (Docker)
Reverse ProxyNginx
Process ManagerSupervisord

Quick Start

Option 1: Local Setup

bash
# Clone the repo
git clone https://github.com/dineshrajupadhya/ZeroToDev.git
cd ZeroToDev/Artificial_Intelligence/doc-qa-chatbot

# Install dependencies
pip install -r requirements.txt

# Start backend (Terminal 1)
cd backend
python run.py

# Start frontend (Terminal 2)
cd frontend
streamlit run app.py

Open http://localhost:8501

Option 2: Docker

bash
docker build -t docqa-chatbot .
docker run -p 7860:7860 docqa-chatbot

Open http://localhost:7860

Option 3: Use Hosted Version

No setup needed — visit [dineshupadhya-docqa-chatbot.hf.space](https://dineshupadhya-docqa-chatbot.hf.space)


API Endpoints

MethodEndpointDescription
GET/api/healthHealth check
GET/api/health/llmLLM loading status
GET/api/modelsList available AI models
POST/api/uploadUpload a single document
POST/api/upload/batchUpload multiple documents
POST/api/askAsk a question (standard)
POST/api/ask/streamAsk a question (SSE streaming)
GET/api/suggestGet suggested questions for documents
POST/api/compareCompare two documents
GET/api/similarityGet vector similarity scores
POST/api/summarizeSummarize text
POST/api/scrapeScrape a URL
GET/api/documentsList all documents
GET/api/chunksBrowse text chunks
GET/api/analyticsDocument analytics
GET/api/stats/{collection}Collection statistics
POST/api/deleteDelete a document
GET/api/sessionsList chat sessions
POST/api/sessionsCreate a session
GET/api/sessions/{id}/historyGet session history
DELETE/api/sessions/{id}Delete a session

Project Structure

doc-qa-chatbot/
├── backend/
│   ├── main.py              # FastAPI server — 20+ endpoints
│   ├── rag.py               # RAG pipeline — LLM, embeddings, vector store
│   ├── config.py            # Environment configuration
│   └── run.py               # Development runner
├── frontend/
│   └── app.py               # Streamlit UI — 8 tabs, voice, streaming
├── Dockerfile               # Multi-service container (nginx + FastAPI + Streamlit)
├── nginx.conf               # Reverse proxy — routes /api/* to FastAPI
├── supervisord.conf         # Process manager — runs nginx, uvicorn, streamlit
├── requirements.txt         # All Python dependencies
└── README.md                # This file

Configuration

Environment Variables

VariableDefaultDescription
OPENAI_API_KEY""OpenAI API key for GPT-3.5 (optional)
EMBEDDING_MODELall-MiniLM-L6-v2HuggingFace embedding model
CHUNK_SIZE500Text chunk size in characters
CHUNK_OVERLAP50Overlap between chunks
API_URLhttp://localhost:8000Backend API URL

License

MIT License — free to use, modify, and distribute.