RAG-PDF-Project / README.md
RAG PDF Assistant
docs: add prominent running Hugging Face UI link
2e44953
|
Raw History Blame Contribute Delete
5.94 kB

A newer version of the Gradio SDK is available: 6.31.0

Upgrade
metadata
title: RAG PDF Assistant
emoji: πŸ“„
colorFrom: blue
colorTo: indigo
sdk: gradio
app_file: app.py
pinned: true

RAG PDF Assistant

A production-ready Retrieval Augmented Generation (RAG) system for interactive PDF analysis and question answering using semantic search and large language models.

🌟 Hosted on HuggingFace Spaces | πŸ“¦ Models from HuggingFace Hub | ⚑ Production Ready

Live UI

Live app (running): Open RAG PDF Assistant

Open in Hugging Face Space

Space page: Hugging Face Space Repository


🎯 Features

  • πŸ“€ PDF Upload - Upload any PDF or use the bundled sample
  • πŸ” Smart Retrieval - FAISS-based vector similarity search over PDF content
  • πŸ€– AI-Powered Answers - FLAN-T5 language model generation (HuggingFace)
  • 🌍 Multilingual Support - 100+ languages via multilingual embeddings
  • ⚑ Fast Performance - ~0.5-1 second per query after model load
  • 🎨 User-Friendly UI - Gradio web interface (no coding needed)
  • βœ… Production Ready - Full error handling, model caching, and validation

πŸš€ Quick Start

Option 1: Local Installation

# Clone repository
git clone https://github.com/YOUR_USERNAME/rag_pdf_project.git
cd rag_pdf_project

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

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py

Open your browser to: http://127.0.0.1:7860

Option 2: HuggingFace Spaces (Cloud)

  1. Create a new Gradio Space on HuggingFace
  2. Upload this repository
  3. The app will deploy automatically!

πŸ“– Usage

Web UI (Recommended)

  1. Load PDF: Click "Use Default PDF" or upload your own
  2. Ask Questions: Type your question
  3. Get Answers: RAG-powered answers appear instantly

CLI Interface

python main.py

πŸ—οΈ Architecture

PDF Upload
    ↓
PDF Loader (PyPDF)
    ↓
Text Chunking (300-word chunks)
    ↓
Embedding (HuggingFace: Multilingual-MiniLM, 384-dim)
    ↓
FAISS Vector Index (L2 distance)
    ↓
User Question
    ↓
Query Embedding + Retrieval (Top-3 chunks)
    ↓
Prompt Building
    ↓
HuggingFace FLAN-T5 Generation (200 tokens max)
    ↓
Answer Display

πŸ“‚ Project Structure

rag_pdf_project/
β”œβ”€β”€ app.py                       # Gradio web UI
β”œβ”€β”€ main.py                      # CLI interface
β”œβ”€β”€ requirements.txt             # Dependencies
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ .gitignore                   # Git configuration
β”‚
β”œβ”€β”€ configs/
β”‚   └── settings.py              # Model & parameter config
β”‚
β”œβ”€β”€ data/documents/
β”‚   └── 1.pdf                    # Sample PDF
β”‚
β”œβ”€β”€ ingestion/                   # PDF processing
β”‚   β”œβ”€β”€ build_index.py
β”‚   β”œβ”€β”€ pdf_loader.py
β”‚   └── chunker.py
β”‚
β”œβ”€β”€ retrieval/                   # Vector search
β”‚   β”œβ”€β”€ embedder.py
β”‚   β”œβ”€β”€ retriever.py
β”‚   └── vector_store.py
β”‚
β”œβ”€β”€ generation/                  # Answer generation
β”‚   β”œβ”€β”€ llm.py
β”‚   └── prompt_builder.py
β”‚
└── pipeline/
    └── rag_pipeline.py

πŸ”§ Configuration

Edit configs/settings.py:

# HuggingFace Embedding Model
EMBED_MODEL = 'paraphrase-multilingual-MiniLM-L12-v2'

# HuggingFace Generation Model
GEN_MODEL = 'google/flan-t5-small'

# Chunking
CHUNK_SIZE = 300  # words

# Retrieval
TOP_K = 3  # chunks

# Generation
MAX_NEW_TOKENS = 200  # tokens

πŸ€– HuggingFace Integration

Models Used

Component Model Source
Embedding paraphrase-multilingual-MiniLM-L12-v2 SentenceTransformers
Generation google/flan-t5-small Google
Tokenizer Auto HuggingFace

Deploy to HuggingFace Spaces

# 1. Login to HuggingFace
huggingface-cli login

# 2. Create Space
huggingface-cli repo create rag-pdf-assistant --type space --space-sdk docker

# 3. Push code
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/rag-pdf-assistant
git push hf main

πŸ“Š Performance

Metric Value
First Query 1.5-2 seconds
Subsequent Queries 0.5-1 second
Model Size ~2GB
Memory Usage 4-6GB

πŸ§ͺ Testing

python app.py
# Click "Use Default PDF"
# Ask: "What is this document about?"

πŸ“š Documentation


πŸ“¦ Dependencies

  • transformers - HuggingFace T5 models
  • sentence-transformers - Multilingual embeddings
  • faiss-cpu - Vector search
  • pypdf - PDF extraction
  • gradio - Web UI
  • numpy - Numerical computing

πŸš€ Deployment

Local

python app.py

Docker

FROM python:3.10
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

HuggingFace Spaces ⭐

Just push to HuggingFace!


πŸ“œ License

MIT License


πŸ™ Acknowledgments

  • HuggingFace - Models and transformers
  • Facebook Research - FAISS
  • Google - FLAN-T5
  • SentenceTransformers - Embeddings
  • Gradio - Web interfaces

Built with ❀️ using HuggingFace models

Made with Transformers β€’ SentenceTransformers β€’ FAISS β€’ Gradio