Spaces:
Sleeping
Sleeping
File size: 3,419 Bytes
1936be9 fffc3d6 1936be9 8b017a0 96bba26 8b017a0 1936be9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
---
title: Document RAG Chatbot
emoji: 🤖
colorFrom: indigo
colorTo: purple
sdk: docker
app_file: flask_app.py
pinned: false
short_description: 'An intelligent chatbot that understands your documents'
---
# Document RAG Chatbot
An intelligent, context-aware chatbot that understands your documents.
Upload a PDF or text file, and it will answer questions using only the information inside — no hallucinations, no fluff.
Built with **Flask**, **LangChain**, and **Google Gemini**, this project demonstrates a clean, modular approach to **Retrieval-Augmented Generation (RAG)** in action.
---
## Highlights
- Upload and analyze **PDF** or **TXT** files
- Uses **FAISS** for fast semantic search
- Embeddings powered by **HuggingFace Sentence Transformer**
- Answers generated by **Gemini 2.5 Flash**
- Works with **frontend-provided API key** (no server-side storage)
- Clean, responsive interface for smooth chat interaction
---
## Tech Stack
| Component | Technology |
|------------|-------------|
| Backend | Flask |
| Language Model | Google Gemini |
| Vector Store | FAISS |
| Embeddings | HuggingFace all-MiniLM-L6-v2 |
| Frontend | HTML, CSS, JavaScript |
| Framework | LangChain |
---
## Getting Started
### 1️⃣ Clone the Repository
```bash
git clone https://huggingface.co/spaces/<your-username>/Document-RAG-System
cd Document-RAG-System
````
### 2️⃣ Set Up Your Environment
```bash
python -m venv venv
# Activate
venv\Scripts\activate # Windows
source venv/bin/activate # macOS/Linux
```
### 3️⃣ Install Dependencies
```bash
pip install -r requirements.txt
```
---
## Run the App
```bash
python flask_app.py
```
Once running, open your browser and go to:
👉 **[http://127.0.0.1:5000/](http://127.0.0.1:5000/)**
---
## Get Your Gemini API Key
1. Visit [Google AI Studio](https://aistudio.google.com/app/apikey)
2. Generate a **Gemini API Key**
3. Paste it in the “API Key” field on the webpage
4. Save and start chatting!
Your key is never stored — it’s used only in your current session.
---
## How It Works
Here’s what happens behind the scenes:
1. You upload your document.
2. The file is split into small chunks (for efficient retrieval).
3. Each chunk is embedded into a vector using HuggingFace embeddings.
4. FAISS indexes these vectors for quick similarity search.
5. When you ask a question, relevant chunks are retrieved and sent to Gemini.
6. Gemini generates a focused, contextual answer — grounded in your document.
That’s **Retrieval-Augmented Generation (RAG)** in a nutshell.
---
## Example Use Cases
- Summarize long reports
- Extract key information from research papers
- Study assistant for textbooks
- Legal, medical, or technical document Q&A
- Analyze and interpret **crypto project whitepapers** — understand tokenomics, roadmap, and team details before investing
---
## Customization
You can tweak:
* `chunk_size` and `chunk_overlap` in `chatbot.py`
* The **system message** for tone or depth
* The **Gemini model** (to `gemini-2.5-flash`, `gemini-1.5-pro`, etc.)
---
## Author
**Williams Odunayo**
*Machine Learning Engineer | Builder of useful AI systems*😉
🔗 [GitHub](https://github.com/Wills17) • [LinkedIn](https://linkedin.com/in/williamsodunayo)
---
## License
Released under the **MIT License**.
Free to use, modify, and build upon - attribution is appreciated. |