| title | Rag Chatbot | |
|---|---|---|
| emoji | 🤖 | |
| colorFrom | blue | |
| colorTo | purple | |
| sdk | docker | |
| app_port | 8501 | |
| tags |
|
|
| pinned | false | |
| short_description | RAG Chatbot that answers questions about any PDF or TXT | |
| license | mit |
Ask questions about any document — get instant AI-powered answers.
🔗 Try it live — no install needed
Note: if the demo shows a temporary scheduling error, it's a known Hugging Face infrastructure issue, not a bug in the app. Refresh in a bit, or run locally using the steps below.
A RAG (Retrieval-Augmented Generation) chatbot that answers questions based on the content of any document. Supports both PDF and TXT files, uses semantic search (via sentence-transformers) to find the most relevant context, and generates answers using Flan-T5, an instruction-tuned model that paraphrases rather than copying text verbatim. Deployed live on Hugging Face Spaces with Docker — no API key needed.
Core idea: Upload your document. Ask it anything. Get instant answers.
- 📄 PDF & TXT Support — Upload any document format
- 🧠 Semantic Search — Finds relevant context using sentence embeddings, not just keyword matching
- 🌐 Web UI — Clean Streamlit interface, live on Hugging Face Spaces
- 💻 CLI Mode — Terminal-based chat, for local/offline use
- 🐳 Dockerized Deployment — Fully containerized and reproducible
- 🔒 Self-contained — No external API key required to run
huggingface.co/spaces/zain-cs/rag-chatbot
Upload a PDF or TXT file, then ask questions about its content directly in your browser.
1. Clone the repository
git clone https://github.com/zain-cs/rag-chatbots.git
cd rag-chatbots2. Create and activate a 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.pyYour Document (PDF or TXT)
│
▼
Chunk the document into passages
│
▼
Embed chunks + question with sentence-transformers
│
▼
Retrieve the most semantically relevant chunk
│
▼
Feed chunk + question to Flan-T5
│
▼
Generated Answer
📦 rag-chatbots
┣ 📂 data
┃ ┗ 📄 sample.txt ← Sample document
┣ 📂 src
┃ ┣ 🐍 chatbot.py ← CLI chatbot
┃ ┣ 🐍 pdf_loader.py ← PDF & TXT loader
┃ ┗ 🐍 semantic_search.py ← Embedding-based chunk retrieval
┣ 🐍 app.py ← Streamlit web UI (deployed entry point)
┣ 🐳 Dockerfile ← Container config for Hugging Face Spaces
┣ 📄 .gitignore
┣ 📄 requirements.txt
┗ 📄 README.md
| Tool | Purpose |
|---|---|
| Python 3.10+ | Core language |
| Flan-T5 (base) | Local instruction-tuned text generation model |
| Sentence-Transformers (MiniLM) | Semantic embeddings for retrieval |
| HuggingFace Transformers | Model loading and inference |
| PyTorch | Deep learning backend |
| Streamlit | Web UI framework |
| PyMuPDF | PDF text extraction |
| Docker | Containerized deployment |
- Document loading and chunking
- Interactive CLI chat loop
- PDF & TXT support
- Streamlit web interface
- Semantic search with embeddings
- Deploy on Hugging Face Spaces
- Upgrade generation model to Flan-T5 (instruction-tuned) for higher answer quality
- Experiment with larger models (Flan-T5-large or an API-based LLM) for even better answer quality
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.
