PDF Copilot is a powerful Retrieval-Augmented Generation (RAG) chatbot that allows users to seamlessly upload PDF documents and ask questions across them. It uses advanced machine learning models to extract paragraphs relevant to your questions and synthesizes natural language answers.
Try it out live here: https://huggingface.co/spaces/HYPERx54/PDF-Chatbot
- Multi-Document Support: Upload multiple PDFs and maintain an organized document library in the sidebar.
- Global & Specific Scope:
- Global Search: Ask questions across your entire library of uploaded PDFs simultaneously. The bot will intelligently fetch relevant sections from multiple documents to construct a comprehensive answer.
- Specific Document Scope: Click on any document in your library to open a dedicated, side-by-side interactive PDF reader. Questions asked in this view are strictly isolated to the selected document.
- Strict Fact-Binding: The AI is strictly prompted to only answer based on the provided document context. It will not hallucinate answers from its pre-trained knowledge base.
- Beautiful Mathematical Rendering: Fully supports and elegantly renders complex mathematical formulas, equations, and expressions using KaTeX.
- Session Privacy: Uploads and chat logs are completely isolated per session. When you close the browser tab, a cleanup beacon securely wipes your temporary files and vector embeddings.
- Backend Framework: FastAPI
- LLM AI Provider: Google Gemini (Gemini 2.5 Flash) via
langchain-google-genai - Embeddings: HuggingFace
sentence-transformers/all-MiniLM-L6-v2(Local generation) - Vector Database: ChromaDB
- Frontend UI: Vanilla JavaScript, HTML, CSS with Lucide Icons and PDF.js
To run this project locally on your machine:
-
Clone the repository:
git clone https://github.com/ShantanuSaurav/AI_Chatbot.git cd AI_Chatbot -
Set up a virtual environment (Optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install the dependencies:
pip install -r requirements.txt
-
Configure your API Keys: Create a folder named
backendand a file inside it called.env.mkdir backend touch backend/.env
Add your Google Gemini API key to the
.envfile:GEMINI_API_KEY=your_gemini_api_key_here
-
Run the application:
python app.py
The app will start on
http://127.0.0.1:8000.
This application is fully compatible with Hugging Face Spaces using the Docker SDK. To deploy it:
- Create a new Space on Hugging Face (SDK: Docker).
- Push this repository's files to the Space.
- Go to the Space Settings -> Variables and secrets.
- Create a new Secret named
GEMINI_API_KEYand paste your Google Gemini API key. - The Space will automatically build and securely inject the keys into the application.
- Vector Database Reset: The current implementation uses an ephemeral/local ChromaDB storage approach. When the server fully shuts down or restarts, previous document embeddings may be lost and require re-uploading.
- Large PDF Processing Time: Very large PDFs (e.g., 100+ pages) might take slightly longer to chunk and embed upon the initial upload since embedding happens synchronously on the CPU.
- Context Window Limitations: While the Global Search increases retrieval depth, extremely complex cross-document reasoning might still miss highly fragmented information if it falls outside the top 25 retrieved chunks.
- Stateless AI Memory: To strictly ensure answers are bound to the document context, the chatbot does not retain conversational memory (chat history context) between different questions. Each question is treated independently against the document.
This project is licensed under the MIT License.