A RAG (Retrieval-Augmented Generation) chatbot that answers questions based on the content of any document. Supports both PDF and TXT files. Runs completely locally — no API key needed.
Core idea: Upload your document. Ask it anything. Get instant answers.
- 📄 PDF & TXT Support — Upload any document format
- 🌐 Web UI — Clean Streamlit interface
- 💻 CLI Mode — Terminal-based chat
- 🔒 100% Local — No API key or internet required
- ⚡ Fast — GPT-2 runs on CPU
Run the web app and chat with your documents through a clean browser UI:
streamlit run app.py📄 Document: AI & Machine Learning Guide
You: What is machine learning?
🤖 Bot: Machine learning is a subset of AI that allows systems to learn from data without being explicitly programmed.
You: What are the types of AI?
🤖 Bot: Narrow AI, General AI, and Super AI.
You: What is TensorFlow?
🤖 Bot: TensorFlow is an open source framework by Google for building machine learning models.
Your Document (PDF or TXT)
│
▼
Chunk the document into paragraphs
│
▼
Find most relevant chunk for the question (keyword matching)
│
▼
Feed chunk + question to GPT-2
│
▼
Generated Answer
1. Clone the repository
git clone https://github.com/zain-cs/rag-chatbots.git
cd rag-chatbots2. Create and activate virtual environment
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Mac/Linux3. Install dependencies
pip install -r requirements.txt4a. Run the Web UI
streamlit run app.py4b. Run the CLI chatbot
python src/chatbot.py📦 rag-chatbots
┣ 📂 data
┃ ┗ 📄 sample.txt ← Sample document
┣ 📂 src
┃ ┣ 🐍 chatbot.py ← CLI chatbot
┃ ┗ 🐍 pdf_loader.py ← PDF & TXT loader
┣ 🐍 app.py ← Streamlit web UI
┣ 📄 .gitignore
┣ 📄 requirements.txt
┗ 📄 README.md
| Tool | Purpose |
|---|---|
| Python 3.10+ | Core language |
| GPT-2 | Local text generation model |
| HuggingFace Transformers | Model loading and inference |
| PyTorch | Deep learning backend |
| Streamlit | Web UI framework |
| PyMuPDF | PDF text extraction |
- Document loading and chunking
- Keyword-based relevant chunk retrieval
- GPT-2 local text generation
- Interactive CLI chat loop
- PDF & TXT support
- Streamlit web interface
- Semantic search with embeddings
- Upgrade to Gemini or GPT-4 API
- Deploy on Hugging Face Spaces
Zain — @zain-cs
Open to freelance ML and AI projects.
This project is licensed under the MIT License — free to use, modify, and build on it.