Update README.md
Browse files
README.md
CHANGED
|
@@ -1,12 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π₯ YouTube RAG Q&A System
|
| 2 |
+
|
| 3 |
+
> **Ask any question about any YouTube video β powered by Retrieval-Augmented Generation**
|
| 4 |
+
|
| 5 |
+
[](https://python.org)
|
| 6 |
+
[](https://groq.com)
|
| 7 |
+
[](https://github.com/facebookresearch/faiss)
|
| 8 |
+
[](https://gradio.app)
|
| 9 |
+
[](LICENSE)
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## What it does
|
| 14 |
+
|
| 15 |
+
Paste a YouTube URL β the system fetches the transcript, chunks it, embeds it into a local FAISS vector database, and lets you have a grounded conversation with the video content via Groq's blazing-fast LLaMA 3.3-70B model.
|
| 16 |
+
|
| 17 |
+
**All processing is free and open-source.** No OpenAI key needed.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## Architecture
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
YouTube URL
|
| 25 |
+
β
|
| 26 |
+
βΌ
|
| 27 |
+
YouTubeTranscriptApi β free, no API key
|
| 28 |
+
β raw transcript text
|
| 29 |
+
βΌ
|
| 30 |
+
RecursiveCharacterTextSplitter β LangChain text splitter
|
| 31 |
+
β ~500-char chunks with 50-char overlap
|
| 32 |
+
βΌ
|
| 33 |
+
SentenceTransformer β all-MiniLM-L6-v2, runs on CPU
|
| 34 |
+
β 384-dim normalised embeddings
|
| 35 |
+
βΌ
|
| 36 |
+
FAISS IndexFlatIP β cosine similarity, in-memory
|
| 37 |
+
β
|
| 38 |
+
ββββ user query (embedded on-the-fly)
|
| 39 |
+
β top-4 most similar chunks retrieved
|
| 40 |
+
βΌ
|
| 41 |
+
Groq LLaMA-3.3-70B-Versatile β 128K context, ~800 tok/s
|
| 42 |
+
β grounded, factual answer
|
| 43 |
+
βΌ
|
| 44 |
+
Gradio UI β two-tab chat interface
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
---
|
| 48 |
+
|
| 49 |
+
## Quickstart (Google Colab)
|
| 50 |
+
|
| 51 |
+
1. Open `youtube_rag_qa.py` in Colab (or copy-paste the cells).
|
| 52 |
+
2. Add your Groq API key to **Colab Secrets** (π icon in left sidebar) as `GROQ_API_KEY`.
|
| 53 |
+
Get a free key at [console.groq.com](https://console.groq.com).
|
| 54 |
+
3. Run the install cell, then the main cell.
|
| 55 |
+
4. Click the Gradio **public link** that appears.
|
| 56 |
+
|
| 57 |
---
|
| 58 |
|
| 59 |
+
## Local setup
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
git clone https://github.com/YOUR_USERNAME/youtube-rag-qa.git
|
| 63 |
+
cd youtube-rag-qa
|
| 64 |
+
|
| 65 |
+
python -m venv .venv
|
| 66 |
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
| 67 |
+
|
| 68 |
+
pip install -r requirements.txt
|
| 69 |
+
|
| 70 |
+
export GROQ_API_KEY="gsk_..." # or create a .env file
|
| 71 |
+
|
| 72 |
+
python youtube_rag_qa.py
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Open `http://localhost:7860` in your browser.
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## Tech stack
|
| 80 |
+
|
| 81 |
+
| Component | Library | Why |
|
| 82 |
+
|-----------|---------|-----|
|
| 83 |
+
| Transcript | `youtube-transcript-api` | Free, no YouTube API key |
|
| 84 |
+
| Embeddings | `sentence-transformers` | Local, CPU-friendly, 384-dim |
|
| 85 |
+
| Vector DB | `faiss-cpu` | Fast similarity search, in-memory |
|
| 86 |
+
| Text split | `langchain-text-splitters` | Robust recursive splitting |
|
| 87 |
+
| LLM | `groq` + LLaMA-3.3-70B | ~800 tok/s, free tier, 128K context |
|
| 88 |
+
| UI | `gradio` 4.x | Fast prototyping, public sharing link |
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## Deployment options
|
| 93 |
+
|
| 94 |
+
### Option A β Hugging Face Spaces (recommended for portfolios)
|
| 95 |
+
1. Create a new Space β Gradio SDK.
|
| 96 |
+
2. Upload `youtube_rag_qa.py` as `app.py` and `requirements.txt`.
|
| 97 |
+
3. Add `GROQ_API_KEY` in Space Settings β Repository secrets.
|
| 98 |
+
4. Free, permanent URL, no server management.
|
| 99 |
+
|
| 100 |
+
### Option B β Vercel + FastAPI backend
|
| 101 |
+
1. Wrap the RAG functions in a FastAPI app (`/api/process`, `/api/chat`).
|
| 102 |
+
2. Build a Next.js frontend calling those endpoints.
|
| 103 |
+
3. Deploy API on Railway/Render (free tier), frontend on Vercel.
|
| 104 |
+
|
| 105 |
+
### Option C β Docker + any cloud
|
| 106 |
+
```dockerfile
|
| 107 |
+
FROM python:3.11-slim
|
| 108 |
+
WORKDIR /app
|
| 109 |
+
COPY requirements.txt .
|
| 110 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 111 |
+
COPY youtube_rag_qa.py .
|
| 112 |
+
CMD ["python", "youtube_rag_qa.py"]
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
---
|
| 116 |
+
|
| 117 |
+
## Student resources you can leverage
|
| 118 |
+
|
| 119 |
+
| Resource | How to use |
|
| 120 |
+
|----------|-----------|
|
| 121 |
+
| **GitHub Student Developer Pack** | Free Namecheap domain + hosting credits |
|
| 122 |
+
| **Azure for Students** | $100 credit β deploy on Azure Container Apps |
|
| 123 |
+
| **Hugging Face** | Free Spaces hosting (always free) |
|
| 124 |
+
| **Groq** | Free API tier (generous rate limits) |
|
| 125 |
+
| **MongoDB Atlas** | Free 512 MB cluster β persist chat history |
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## Roadmap (upgrade ideas)
|
| 130 |
+
|
| 131 |
+
- [ ] Persistent FAISS index saved to disk between sessions
|
| 132 |
+
- [ ] Multi-video support β query across several videos at once
|
| 133 |
+
- [ ] Timestamp citations β show where in the video the answer comes from
|
| 134 |
+
- [ ] Streaming LLM responses (Groq supports SSE streaming)
|
| 135 |
+
- [ ] Chat history saved per session to MongoDB Atlas
|
| 136 |
+
- [ ] Docker + GitHub Actions CI/CD
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
## License
|
| 141 |
+
|
| 142 |
+
MIT β free to use, modify, and deploy.
|