File size: 1,876 Bytes
9cb6cfa
ef5cc47
9370738
 
 
0ffbaa2
9370738
9cb6cfa
624a099
9cb6cfa
 
9370738
9cb6cfa
9370738
9cb6cfa
9370738
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: PDF Chatbot
emoji: πŸ“˜
colorFrom: blue
colorTo: purple
sdk: streamlit
app_port: 7860
pinned: false
license: mit
---

# πŸ“˜ PDF RAG Chatbot (Groq + LangChain)

A **Retrieval-Augmented Generation (RAG)** application that allows users to:

- Upload a **PDF**
- Ask questions based **only on the PDF content**
- Get accurate answers powered by **Groq LLMs**
- Runs fully on **CPU (Hugging Face Free Tier)**

---

## πŸš€ Features

- πŸ“„ PDF upload & processing
- βœ‚οΈ Intelligent text chunking
- πŸ” Semantic search using embeddings
- 🧠 Context-aware LLM responses
- 🧹 Memory clear & health endpoints
- ⚑ Fast inference via **Groq API**

---

## 🧱 Tech Stack

- **Frontend**: Streamlit
- **Backend**: FastAPI
- **LLM**: Groq (`llama-3.1-8b-instant`)
- **Embeddings**: `all-MiniLM-L6-v2`
- **Vector DB**: Chroma (in-memory)
- **Frameworks**: LangChain
- **Deployment**: Docker + Hugging Face Spaces

---

## πŸ§ͺ How It Works (RAG Pipeline)

1. Upload PDF
2. Split text into chunks
3. Generate embeddings
4. Store in vector database
5. Retrieve relevant chunks
6. Generate answer using Groq LLM

---

## πŸ–₯️ Usage

1. Upload a PDF file
2. Ask questions related to the document
3. If the answer is not in the PDF, the assistant will reply:
   > **"I cannot find this in the PDF."**

---

## πŸ” Environment Variables

The following secret **must** be added in Hugging Face Spaces:

| Variable | Description |
|--------|------------|
| `GROQ_API_KEY` | Groq API key |

> ⚠️ Do NOT commit `.env` files to the repository.

---

## ❀️ Notes

- Runs on **CPU only** (no GPU required)
- Free-tier friendly
- First load may take a few minutes
- Space may sleep when idle

---

## πŸ‘¨β€πŸ’» Author

**Abhishek Saxena**  
M.Tech Data Science, IIT Roorkee  

---

## ⭐ If you like this project

Give it a ⭐ on Hugging Face and feel free to fork!