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
 
 
 
 
 
 
 
 
 
 
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
---
title: AI Powered YouTube Transcript Tutor
emoji: πŸš€
colorFrom: red
colorTo: red
sdk: streamlit
app_file: src/streamlit_app.py
app_port: 8501
tags:
- streamlit
pinned: false
short_description: Streamlit template space
license: mit
---

# πŸŽ“ AI-Powered YouTube Transcript Tutor

A sophisticated Streamlit application that transforms YouTube videos into interactive learning experiences using AI. Ask questions about video content and get intelligent answers based on the transcript.

![Python](https://img.shields.io/badge/python-v3.8+-blue.svg)
![Streamlit](https://img.shields.io/badge/streamlit-v1.28+-red.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)

## πŸš€ Live Demo

**Try the app now:** [https://ai-powered-youtube-transcript-tutor.streamlit.app/](https://ai-powered-youtube-transcript-tutor.streamlit.app/)

Experience the full functionality without any setup required!

## 🌟 Features

### Core Functionality
- **YouTube Transcript Extraction**: Automatically extracts transcripts from YouTube videos
- **AI-Powered Q&A**: Ask questions about video content and get intelligent responses
- **Multi-language Support**: Supports transcripts in multiple languages
- **Video Metadata Display**: Shows video information including title, author, duration, and views

### Enhanced UI/UX
- **Modern Dark Theme**: Clean, professional interface with dark theme
- **Responsive Layout**: Works seamlessly on desktop and mobile devices
- **Loading Indicators**: Visual feedback during processing
- **Sidebar Navigation**: Easy access to processed videos and settings
- **Progress Bars**: Real-time processing status updates

### Advanced Features
- **Multiple Video Processing**: Handle multiple videos in a single session
- **Chat History**: Persistent conversation history with export options
- **Export Functionality**: Export Q&A sessions as PDF, text, or JSON
- **Transcript Download**: Download video transcripts for offline use
- **Fallback System**: Works even when OpenAI API quota is exceeded
- **Session Management**: Advanced session state management

## πŸš€ Quick Start

> **πŸ’‘ Want to try it first?** Check out the [live demo](https://ai-powered-youtube-transcript-tutor.streamlit.app/) - no installation required!

### Prerequisites
- Python 3.8 or higher
- OpenAI API key

### Installation

1. **Clone the repository**
   ```bash
   git clone https://github.com/midlaj-muhammed/AI-Powered-YouTube-Transcript-Tutor.git
   cd AI-Powered-YouTube-Transcript-Tutor
   ```

2. **Create virtual environment**
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

3. **Install dependencies**
   ```bash
   pip install -r requirements.txt
   ```

4. **Set up environment variables**
   ```bash
   # Create .env file
   echo "OPENAI_API_KEY=your_openai_api_key_here" > .env
   ```

5. **Run the application**
   ```bash
   streamlit run app.py
   ```

## πŸ”§ Configuration

### Environment Variables
- `OPENAI_API_KEY`: Your OpenAI API key for AI-powered responses

### Streamlit Configuration
The app includes custom Streamlit configuration in `.streamlit/config.toml` for optimal performance.

## πŸ“± Usage

1. **Enter YouTube URL**: Paste any YouTube video URL in the input field
2. **Process Video**: Click "πŸš€ Process Video" to extract and analyze the transcript
3. **Ask Questions**: Use the Q&A interface to ask about the video content
4. **Export Results**: Export conversations in multiple formats
5. **Manage Sessions**: Use sidebar to navigate between processed videos

## πŸ—οΈ Project Structure

```
AI-Powered-YouTube-Transcript-Tutor/
β”œβ”€β”€ app.py                      # Main Streamlit application
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ README.md                   # Project documentation
β”œβ”€β”€ .env.example               # Environment variables template
β”œβ”€β”€ .streamlit/
β”‚   └── config.toml            # Streamlit configuration
β”œβ”€β”€ static/
β”‚   └── style.css              # Custom CSS styling
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── utils/
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ youtube_handler.py  # YouTube processing
β”‚       β”œβ”€β”€ text_processor.py   # AI text processing
β”‚       β”œβ”€β”€ session_manager.py  # Session management
β”‚       β”œβ”€β”€ export_utils.py     # Export functionality
β”‚       └── logger.py          # Logging utilities
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── settings.py            # Application settings
└── logs/                      # Application logs
```

## 🌐 Deployment

### Hugging Face Spaces
This application is optimized for deployment on Hugging Face Spaces:

1. Create a new Space on [Hugging Face](https://huggingface.co/spaces)
2. Choose Streamlit SDK
3. Upload all project files
4. Set `OPENAI_API_KEY` in Repository secrets
5. Your app will be live in minutes!

### Local Development
```bash
streamlit run app.py --server.port 8501
```

## πŸ”’ Privacy & Security

- **No Data Storage**: Conversations are only stored in your browser session
- **Secure Processing**: All API calls are made securely
- **Privacy First**: No personal data is collected or stored

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ™ Acknowledgments

- [Streamlit](https://streamlit.io/) for the amazing web app framework
- [OpenAI](https://openai.com/) for the powerful AI capabilities
- [YouTube Transcript API](https://github.com/jdepoix/youtube-transcript-api) for transcript extraction

## πŸ“ž Support

If you encounter any issues or have questions, please [open an issue](https://github.com/midlaj-muhammed/AI-Powered-YouTube-Transcript-Tutor/issues).

---

**Made with ❀️ using Streamlit and OpenAI**

## ✨ Features

### Core Functionality
- **YouTube Transcript Extraction**: Automatically extracts transcripts from YouTube videos
- **AI-Powered Q&A**: Ask questions about video content and get intelligent responses
- **Multi-language Support**: Supports transcripts in multiple languages
- **Video Metadata Display**: Shows video information including title, author, duration, and views

### Enhanced UI/UX
- **Modern Design**: Clean, professional interface with custom CSS styling
- **Responsive Layout**: Works seamlessly on desktop and mobile devices
- **Loading Indicators**: Visual feedback during processing
- **Sidebar Navigation**: Easy access to processed videos and settings
- **Progress Bars**: Real-time processing status updates

### Advanced Features
- **Multiple Video Processing**: Handle multiple videos in a single session
- **Chat History**: Persistent conversation history with export options
- **Export Functionality**: Export Q&A sessions as PDF, text, or JSON
- **Transcript Download**: Download video transcripts for offline use
- **Caching System**: Intelligent caching for improved performance
- **Database Integration**: SQLite database for storing processed videos and conversations

### Technical Improvements
- **Error Handling**: Comprehensive error handling and user feedback
- **Input Validation**: Robust YouTube URL validation
- **Session Management**: Advanced session state management
- **Logging System**: Detailed logging for debugging and monitoring
- **Configuration Management**: Flexible configuration via YAML and environment variables

## πŸš€ Quick Start

### Prerequisites
- Python 3.8 or higher
- OpenAI API key
- Git (for cloning the repository)

### Installation

1. **Clone the repository**
   ```bash
   git clone https://github.com/yourusername/youtube-transcript-chatbot.git
   cd youtube-transcript-chatbot
   ```

2. **Create a virtual environment**
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

3. **Install dependencies**
   ```bash
   pip install -r requirements.txt
   ```

4. **Set up environment variables**
   ```bash
   cp .env.template .env
   # Edit .env file and add your OpenAI API key
   ```

5. **Run the application**
   ```bash
   streamlit run app.py
   ```

6. **Open your browser**
   Navigate to `http://localhost:8501`

## πŸ”§ Configuration

### Environment Variables

Create a `.env` file based on `.env.template`:

```env
# Required
OPENAI_API_KEY=your_openai_api_key_here

# Optional
LOG_LEVEL=INFO
CACHE_DIRECTORY=cache
DATABASE_PATH=data/chatbot.db
MAX_CACHE_SIZE_MB=500
```

### Configuration File

Modify `config/config.yaml` to customize application behavior:

```yaml
app:
  title: "AI-Powered YouTube Transcript Tutor"
  description: "Ask questions from YouTube lecture transcripts using AI"

processing:
  default_chunk_size: 1000
  chunk_overlap: 200
  supported_languages: ["en", "es", "fr", "de", "it", "pt", "ru", "ja", "ko", "zh"]

ai:
  model_temperature: 0.7
  max_tokens: 2000
  retrieval_k: 4
```

## πŸ“– Usage Guide

### Processing a Video

1. **Enter YouTube URL**: Paste a YouTube video URL in the input field
2. **Click Process Video**: The application will:
   - Extract the video transcript
   - Display video metadata
   - Create an AI knowledge base
   - Enable Q&A functionality

### Asking Questions

1. **Enter your question** in the text input field
2. **Click Ask** to get an AI-generated answer
3. **View source references** to see which parts of the transcript were used

### Managing Sessions

- **View processed videos** in the sidebar
- **Switch between videos** by clicking on video titles
- **Export chat history** in PDF, text, or JSON format
- **Clear chat history** using the sidebar button

### Advanced Features

- **Language Selection**: Choose transcript language in settings
- **Export Options**: Download transcripts and chat histories
- **Cache Management**: Automatic caching for improved performance
- **Database Storage**: Persistent storage of processed videos and conversations

## 🐳 Docker Deployment

### Using Docker Compose (Recommended)

1. **Create environment file**
   ```bash
   cp .env.template .env
   # Add your OpenAI API key to .env
   ```

2. **Build and run**
   ```bash
   docker-compose up -d
   ```

3. **Access the application**
   Open `http://localhost:8501`

### Using Docker

1. **Build the image**
   ```bash
   docker build -t youtube-chatbot .
   ```

2. **Run the container**
   ```bash
   docker run -p 8501:8501 -e OPENAI_API_KEY=your_key_here youtube-chatbot
   ```

## πŸ§ͺ Testing

Run the test suite:

```bash
# Install development dependencies
pip install -e .[dev]

# Run tests
pytest

# Run tests with coverage
pytest --cov=src

# Run specific test file
pytest tests/test_youtube_handler.py
```

## πŸ“ Project Structure

```
youtube-transcript-chatbot/
β”œβ”€β”€ app.py                      # Main Streamlit application
β”œβ”€β”€ src/                        # Source code
β”‚   β”œβ”€β”€ utils/                  # Utility modules
β”‚   β”‚   β”œβ”€β”€ youtube_handler.py  # YouTube operations
β”‚   β”‚   β”œβ”€β”€ text_processor.py   # Text processing and AI
β”‚   β”‚   β”œβ”€β”€ session_manager.py  # Session management
β”‚   β”‚   β”œβ”€β”€ export_utils.py     # Export functionality
β”‚   β”‚   β”œβ”€β”€ database.py         # Database operations
β”‚   β”‚   β”œβ”€β”€ cache_manager.py    # Caching system
β”‚   β”‚   └── logger.py           # Logging configuration
β”œβ”€β”€ config/                     # Configuration files
β”‚   β”œβ”€β”€ config.yaml            # Application configuration
β”‚   └── settings.py            # Settings management
β”œβ”€β”€ static/                     # Static assets
β”‚   └── style.css              # Custom CSS styles
β”œβ”€β”€ tests/                      # Test files
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ .env.template             # Environment template
β”œβ”€β”€ Dockerfile                # Docker configuration
β”œβ”€β”€ docker-compose.yml        # Docker Compose configuration
└── README.md                 # This file
```

## πŸ” Troubleshooting

### Common Issues

1. **OpenAI API Key Error**
   - Ensure your API key is correctly set in the `.env` file
   - Check that you have sufficient API credits

2. **YouTube Video Not Found**
   - Verify the URL is correct and the video is public
   - Some videos may have transcripts disabled

3. **Transcript Not Available**
   - Try selecting a different language in settings
   - Some videos may not have auto-generated transcripts

4. **Performance Issues**
   - Clear cache using the sidebar option
   - Reduce chunk size in configuration
   - Check available disk space

### Getting Help

- Check the logs in the `logs/` directory
- Enable debug mode by setting `LOG_LEVEL=DEBUG` in `.env`
- Review the application configuration in `config/config.yaml`

## πŸš€ Deployment Options

### Local Development
- Use `streamlit run app.py` for development
- Enable debug mode for detailed logging

### Production Deployment

#### Streamlit Cloud
1. Push code to GitHub repository
2. Connect to Streamlit Cloud
3. Add secrets for environment variables

#### Heroku
1. Create `Procfile`: `web: streamlit run app.py --server.port=$PORT`
2. Set environment variables in Heroku dashboard
3. Deploy using Git or GitHub integration

#### AWS/GCP/Azure
- Use Docker container deployment
- Set up load balancer for high availability
- Configure environment variables in cloud console

## 🀝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ™ Acknowledgments

- [Streamlit](https://streamlit.io/) for the amazing web framework
- [LangChain](https://langchain.com/) for AI/ML capabilities
- [OpenAI](https://openai.com/) for the language models
- [YouTube Transcript API](https://github.com/jdepoix/youtube-transcript-api) for transcript extraction

## πŸ“Š Performance Tips

### Optimization Recommendations
- **Use caching**: Enable vectorstore caching for frequently accessed videos
- **Adjust chunk size**: Smaller chunks (500-800) for better precision, larger (1200-1500) for broader context
- **Monitor memory**: Clear cache periodically for long-running sessions
- **Database maintenance**: Regularly clean up old conversations and videos

### Scaling Considerations
- **Horizontal scaling**: Use multiple instances behind a load balancer
- **Database optimization**: Consider PostgreSQL for high-volume deployments
- **Caching layer**: Implement Redis for distributed caching
- **API rate limiting**: Monitor OpenAI API usage and implement rate limiting

## πŸ“ž Support

For support, please open an issue on GitHub or contact the development team.

---

Made with ❀️ by the YouTube Transcript Chatbot Team