An intelligent chat interface that appears on YouTube videos, allowing you to have AI-powered conversations about the video content using advanced RAG (Retrieval-Augmented Generation) technology.
- Automatic Transcript Processing: Extracts and processes YouTube video transcripts
- Context-Aware Responses: AI understands and responds based on actual video content
- Intelligent Chunking: Breaks down long videos into manageable pieces for better comprehension
- Beautiful UI Design: Modern gradient design with smooth animations
- Real-time Typing Indicators: Shows when AI is processing your question
- Persistent Chat History: Maintains conversation context throughout the video
- Mobile-Friendly: Responsive design that works on all devices
- RAG Technology: Uses Retrieval-Augmented Generation for accurate responses
- Multi-Model Support: Powered by Google's Gemini AI
- Vector Search: FAISS-based semantic search for relevant content retrieval
- Context Preservation: Remembers previous conversation for coherent discussions
graph TD
A[YouTube Video] --> B[Transcript Extraction]
B --> C[Text Chunking]
C --> D[Vector Embeddings]
D --> E[FAISS Vector Store]
%% User input triggers parallel processing
J[User Question] --> P[RunnableParallel]
%% Three parallel operations
P --> F[Context: Semantic Search]
P --> Q[Question: PassThrough]
P --> H[Chat History: Format]
%% Context retrieval path
E --> F
F --> FC[Format Retrieved Docs]
%% Chat history path
K[Stored Chat History] --> H
%% All three converge to prompt
FC --> PR[Prompt Template]
Q --> PR
H --> PR
%% Final AI processing
PR --> AI[Gemini AI]
AI --> I[Chat Response]
%% Store response back to history
I --> K
style P fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
style F fill:#e1f5fe
style Q fill:#e1f5fe
style H fill:#e1f5fe
- Frontend: Vanilla JavaScript with modern CSS
- Backend: Flask + Python
- AI Models: Google Gemini AI
- Embeddings: HuggingFace Sentence Transformers
- Vector Store: FAISS
- Framework: LangChain for RAG pipeline
- Python 3.8+
- Google API Key (for Gemini)
- Modern web browser
- YouTube videos with available transcripts
# Clone the repository
git clone <your-repo-url>
cd youtube-chat-extension
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export GOOGLE_API_KEY="your-gemini-api-key"
export GEMINI_MODEL="gemini-pro" # or gemini-1.5-flash
# Run the Flask server
python app.pyOption A: Browser Extension (Recommended)
- Create a new browser extension
- Add the JavaScript code to your content script
- Load the extension in developer mode
Option B: Userscript
- Install Tampermonkey or Greasemonkey
- Create a new userscript with the provided JavaScript
- Enable the script for YouTube domains
Option C: Browser Console
- Open YouTube video
- Open browser developer tools (F12)
- Paste the JavaScript code in console
- Press Enter to activate
- Navigate to any YouTube video
- Look for the floating "๐ฌ Chat about this video" button (top-right)
- Click the button to open the chat interface
- Start chatting about the video content!
๐ค You: What is the main topic of this video?
๐ค AI: Based on the transcript, this video discusses machine learning fundamentals, specifically covering neural networks and deep learning concepts.
๐ค You: Can you explain the part about backpropagation?
๐ค AI: The video explains backpropagation as the process where the neural network learns by calculating errors and adjusting weights backward through the network layers...
| Feature | Description |
|---|---|
| ๐ฏ Context-Aware | AI responds based on actual video content |
| ๐ญ Memory | Remembers previous questions in the conversation |
| โก Real-time | Instant responses with typing indicators |
| ๐จ Beautiful UI | Modern design with smooth animations |
| ๐ฑ Responsive | Works on desktop and mobile devices |
# Required
GOOGLE_API_KEY=your-gemini-api-key-here
GEMINI_MODEL=gemini-pro
# Optional
FLASK_ENV=development
FLASK_DEBUG=True# In app.py, you can customize:
# Embedding model
EMBEDDING_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"
# Chunk settings
chunk_size = 1000
chunk_overlap = 200
# Retrieval settings
search_kwargs = {"k": 2} # Number of relevant chunks to retrieve// In the JavaScript file, customize:
// Button position
top: 100px;
right: 20px;
// Chat box size
width: 380px;
height: 500px;
// Color scheme
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);POST /chat
Content-Type: application/json
{
"video_id": "dQw4w9WgXcQ",
"message": "What is this video about?"
}Response:
{
"response": "This video is about..."
}GET /healthResponse:
{
"status": "ok"
}youtube-chat-extension/
โโโ ๐ app.py # Flask backend server
โโโ ๐ content-script.js # Frontend chat interface
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ README.md # This file
โโโ ๐ assets/ # Images and demos
- Transcript Processing: Extracts and chunks YouTube transcripts
- Vector Store: Creates searchable embeddings using FAISS
- RAG Pipeline: Retrieves relevant context and generates responses
- Chat Interface: Modern UI for seamless user interaction
- Memory Management: Maintains conversation history per video
| Issue | Solution |
|---|---|
| ๐ซ "No transcript available" | Video doesn't have captions - try another video |
| ๐ "Connection error" | Ensure Flask server is running on localhost:5000 |
| ๐ "API key error" | Check your Google API key is valid and set correctly |
| ๐พ "Memory issues" | Restart the server to clear chat history |
# Enable debug logging
export FLASK_DEBUG=True
python app.py
# Check server logs for detailed error informationWe welcome contributions! Here's how you can help:
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature) - ๐ฌ Commit your changes (
git commit -m 'Add amazing feature') - ๐ค Push to the branch (
git push origin feature/amazing-feature) - ๐ Open a Pull Request
- Follow PEP 8 for Python code
- Use meaningful commit messages
- Add tests for new features
- Update documentation as needed
- ๐ค Google Gemini AI - For powerful language understanding
- ๐ค HuggingFace - For sentence transformers
- ๐ฆ LangChain - For RAG framework
- ๐บ YouTube - For transcript API access
- ๐จ CSS Gradients - For beautiful UI design
โญ Star this repo if you found it helpful! โญ
Made with โค๏ธ by Aayush Raj Pokhrel