Skip to content

zain-cs/rag-chatbots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title Rag Chatbot
emoji 🤖
colorFrom blue
colorTo purple
sdk docker
app_port 8501
tags
streamlit
pinned false
short_description RAG Chatbot that answers questions about any PDF or TXT
license mit

🤖 RAG Chatbot

Ask questions about any document — get instant AI-powered answers.

Live Demo Python HuggingFace PyTorch Streamlit Docker Status License

🔗 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.

---
RAG Chatbot Demo

📌 Overview

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.


✨ Features

  • 📄 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

🚀 Live Demo

huggingface.co/spaces/zain-cs/rag-chatbot

Upload a PDF or TXT file, then ask questions about its content directly in your browser.


🖥️ Running Locally

1. Clone the repository

git clone https://github.com/zain-cs/rag-chatbots.git
cd rag-chatbots

2. Create and activate a virtual environment

python -m venv venv

venv\Scripts\activate      # Windows
source venv/bin/activate   # Mac/Linux

3. Install dependencies

pip install -r requirements.txt

4a. Run the Web UI

streamlit run app.py

4b. Run the CLI chatbot

python src/chatbot.py

🔍 How RAG Works

Your 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

🗂️ Project Structure

📦 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

🛠️ Tech Stack

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

🗺️ Roadmap

  • 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

👤 Author

Zain@zain-cs

Open to freelance ML and AI projects.


📄 License

This project is licensed under the MIT License — free to use, modify, and build on it.

About

RAG chatbot that answers questions from any PDF or TXT document using semantic search (sentence-transformers) and Flan-T5. Runs locally or as a live Docker deployment on Hugging Face Spaces — no API key needed.

Topics

Resources

License

Stars

5 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors