This project is a Retrieval-Augmented Generation (RAG) based Question-Answering system. It uses a language model to answer questions based on the content of a provided PDF or text file. The system is built with a FastAPI backend and a Next.js frontend.
- File Upload: Upload PDF or text files to be used as the knowledge base.
- Question-Answering: Ask questions about the content of the uploaded file and get detailed answers.
- Dynamic UI: The user interface is built with Next.js + React and provides a ChatGPT-style experience.
- Markdown, LaTeX & Code Rendering: Responses render Markdown, KaTeX equations, tables, and syntax-highlighted code blocks.
- Responsive Layout: Optimised for both desktop and mobile viewing.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.9+
- Pip (or Conda)
- Node.js 18+
Setup Using uv
-
Clone the repository:
git clone https://github.com/Ghost-141/PDF-QA-System.git cd PDF-QA-System -
Create a virtual environment (recommended):
uv sync .\.venv\Scripts\activate # Windows source .venv/bin/activate # macOS / Linux
-
Install the dependencies:
pip install -r requirements.txt
-
Clone the repository:
git clone https://github.com/Ghost-141/PDF-QA-System.git cd PDF-QA-System -
Create a Conda environment:
conda create --name pdf_qa python=3.9.23 conda activate pdf_qa
-
Install the dependencies:
pip install -r requirements.txt
-
Install the frontend dependencies:
cd frontend npm install
For GPU acceleration, you need to install PyTorch with CUDA support. Make sure you have the correct NVIDIA drivers and CUDA Toolkit version installed.
-
Check your NVIDIA driver and CUDA version: You can check your NVIDIA driver version by running
nvidia-smiin your terminal. This will also show the highest version of CUDA that is supported. -
Install PyTorch with CUDA: Visit the PyTorch website to find the correct command for your specific CUDA version. For example, to install PyTorch with CUDA 12.6, you would run:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
Note: Using a version of PyTorch with CUDA support is essential for running the model on an NVIDIA GPU. If you do not have a compatible GPU, the embedding model will run on the CPU, which will be significantly slower while processing the pdf.
Create a .env file in the root of the project and add your keys:
GROQ_API_KEY=your-groq-api-key
GROQ_MODEL_NAME=openai/gpt-oss-120b # optional override
Uploads are stored in data/raw and the vector database persists in data/vector_db (created automatically).
Start the backend and frontend in separate terminals.
uvicorn backend.main:app --reloadThe API is available at http://localhost:8000.
cd frontend
npm install # first time only
npm run devThe UI is available at http://localhost:3000.
Tip: Set
NEXT_PUBLIC_API_URLinsidefrontend/.env.localif your API is not running on the default host/port.
backend/main.py: FastAPI app factory and CORS setup.backend/api/: API routers for files and QA (/upload-file,/process-file,/ask).backend/services/: File processing, vector store management, QA pipeline, uploads.backend/data/: Runtime data;data/rawfor uploads,data/vector_dbfor Chroma persistence.frontend/: Next.js client.
- Upload a file: Use the upload card in the UI to select a PDF or text file.
- Process the file: Click "Upload & Process" to push the file to the backend and populate the vector store.
- Ask a question: Type your question in the chat composer. Responses appear in a ChatGPT-style transcript with full formatting.
The FastAPI backend provides the following endpoints:
POST /upload-file: Accepts a multipart file upload and stores it indata/raw.- Form Field:
file(UploadFile, required) - Success Response:
{"filename": "<stored-filename>"}
- Form Field:
POST /process-file: Processes a previously uploaded file.- Query Parameter:
filename(string, required) - Success Response:
{"message": "File '<filename>' processed...", "num_docs": <number>} - Error Response:
{"detail": "File '<filename>' not found..."}
- Query Parameter:
POST /ask: Asks a question to the model.- Request Body:
{"query": "<your-question>"} - Success Response:
{"answer": "<model-answer>"} - Error Response:
{"detail": "QA pipeline not initialized..."}
- Request Body:
- Support for Bangla Languge
- Process Images and Complex Pdf
- Support for different documents
- Local llm support