File size: 5,238 Bytes
66d10f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# πŸ”¬ LectureLens AI β€” Complete Setup Guide

## πŸ“ Project Structure
lecturelens/
β”œβ”€β”€ app.py                    # Main Flask app + all API routes
β”œβ”€β”€ requirements.txt          # All Python dependencies
β”œβ”€β”€ Dockerfile               # HuggingFace deployment config
β”œβ”€β”€ .env                     # API keys (NEVER upload this!)
β”œβ”€β”€ .gitignore               # Tells git to ignore .env
β”œβ”€β”€ README.md                # Project documentation
β”œβ”€β”€ SETUP_GUIDE.md           # This file
β”œβ”€β”€ templates/
β”‚   └── index.html           # Complete frontend UI
└── utils/
β”œβ”€β”€ init.py          # Package init
β”œβ”€β”€ transcript_handler.py # YouTube transcript + title extraction
β”œβ”€β”€ embedder.py          # TF-IDF search engine
└── llm_handler.py       # GPT-4o-mini β€” all AI features

---

## πŸ”‘ API Keys Required

### OpenAI API Key (Only One Required!)
1. Go to: https://platform.openai.com
2. Sign up / Login
3. Click "API Keys" β†’ "Create new secret key"
4. Copy your key (starts with `sk-`)

---

## πŸ–₯️ Local Setup

### Step 1: Install Python
Download from: https://python.org (Python 3.10+)

### Step 2: Download Project
Download and extract the project folder

### Step 3: Create Virtual Environment
```bash
# Windows
python -m venv venv
venv\Scripts\activate

# Mac/Linux
python3 -m venv venv
source venv/bin/activate
```

### Step 4: Install Dependencies
```bash
pip install -r requirements.txt
```

### Step 5: Create `.env` File
Create a file named `.env` in the project root:
OPENAI_API_KEY=sk-your-key-here
SECRET_KEY=lecturelens-secret-2024

### Step 6: Create `.gitignore` File
.env
pycache/
*.pyc
venv/

### Step 7: Run the App
```bash
python app.py
```

### Step 8: Open Browser
http://localhost:7860

---

## 🎯 How to Use

### 1. Process a Video
- Paste any YouTube lecture URL
- Click "Analyze Video"
- Wait for transcript extraction

### 2. Generate Study Material
- Click **Summary** β†’ Generate ✨ β†’ Get comprehensive summary
- Click **Flashcards** β†’ Generate ✨ β†’ Get 10 Q&A cards
- Click **Sticky Notes** β†’ Generate ✨ β†’ Get 8 key point notes
- Click **Flowchart** β†’ Generate ✨ β†’ Get concept map
- Click **Quiz** β†’ Generate ✨ β†’ Get 5 MCQ questions

### 3. Chat with AI
- Type any question about the lecture
- AI answers strictly based on video content
- Previous questions are remembered in conversation

### 4. Export Content
- Click πŸ“„ PDF button on any panel to download
- Click πŸ“‹ Copy button to copy to clipboard

### 5. Compare Videos
- Go to Compare tab
- Enter second YouTube URL
- Click Compare ✨

### 6. Change Language
- Click English / اردو / Roman Urdu buttons at top
- All generated content will be in selected language

---

## 🌐 How It Works β€” Technical Flow
User enters YouTube URL
↓
youtube-transcript-api β†’ extracts captions (free)
↓
yt-dlp β†’ fetches video title (free)
↓
TF-IDF (scikit-learn) β†’ splits into chunks, builds search index (free, local)
↓
User asks question / clicks Generate
↓
TF-IDF β†’ finds most relevant transcript chunks
↓
GPT-4o-mini β†’ generates answer from chunks (paid, ~$0.01/session)
↓
Response shown in UI

---

## πŸ“š Libraries Explained

| Library | Purpose | Cost |
|---------|---------|------|
| `flask` | Web server + API endpoints | FREE |
| `youtube-transcript-api` | Extract YouTube captions | FREE |
| `yt-dlp` | Fetch video title | FREE |
| `scikit-learn` | TF-IDF text search | FREE |
| `openai` | GPT-4o-mini AI responses | ~$0.01/session |
| `reportlab` | PDF generation | FREE |
| `python-dotenv` | Load .env API keys | FREE |
| `gunicorn` | Production server | FREE |

---

## πŸš€ Deploy to HuggingFace Spaces (FREE Hosting)

### Step 1: Create HuggingFace Account
Go to: https://huggingface.co β€” sign up free

### Step 2: Create New Space
1. Click profile β†’ "New Space"
2. Name: `lecturelens-ai`
3. SDK: **Docker**
4. Visibility: Public (free)
5. Click "Create Space"

### Step 3: Upload Files
Upload all project files EXCEPT `.env` file

### Step 4: Add Secret Key
1. Go to Space β†’ Settings β†’ Repository Secrets
2. Add:
   - Name: `OPENAI_API_KEY`
   - Value: `sk-your-key-here`

### Step 5: Deploy
HuggingFace automatically builds and deploys!

Your app: `https://huggingface.co/spaces/YOUR_USERNAME/lecturelens-ai`

---

## ❌ Common Errors & Fixes

| Error | Fix |
|-------|-----|
| `No transcript found` | Video does not have captions enabled |
| `OPENAI_API_KEY not set` | Check .env file |
| `Module not found` | Run `pip install -r requirements.txt` |
| `Port already in use` | Change port in app.py or kill existing process |
| `Invalid YouTube URL` | Make sure URL has `watch?v=` or `youtu.be/` |

---

## ⚠️ Important Notes

- Never upload `.env` file to GitHub or HuggingFace
- Videos must have captions/subtitles enabled
- Session data resets when server restarts
- Supports English, Hindi, Urdu transcripts
- AI answers strictly based on video content only

---

## πŸ’° Cost

| Component | Cost |
|-----------|------|
| Everything except OpenAI | FREE |
| OpenAI GPT-4o-mini | ~$0.01 per lecture session |
| HuggingFace hosting | FREE |
| **Total per session** | **~$0.01** |

---