A powerful Retrieval-Augmented Generation (RAG) tool that lets you chat with any YouTube channel's video transcripts using Google's Gemini API and Apify's YouTube scraper.
- 📺 Scrape videos from any YouTube channel
- 📝 Extract video transcripts and subtitles
- ☁️ Upload to Gemini File Search for semantic search
- 💬 Interactive chat interface to query video content
- 🔍 Smart retrieval of relevant information from transcripts
- Python 3.8 or higher
- Gemini API key (Get one here)
- Apify API token (Get one here)
-
Clone the repository
git clone <your-repo-url> cd gemini-api-rag
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env
Edit
.envand add your API keys:GEMINI_API_KEY=your_gemini_api_key_here APIFY_API_TOKEN=your_apify_api_token_here
Run the tool:
python youtube_rag.pyThe tool will prompt you for:
- YouTube Channel URL - The full URL of the channel (e.g.,
https://www.youtube.com/@channelname) - Number of videos - How many recent videos to process
🎥 YouTube Channel RAG Tool
================================================================================
📺 Enter YouTube channel URL: https://www.youtube.com/@example
🔢 How many videos to process (newest first): 10
🔍 Scraping channel: https://www.youtube.com/@example
📊 Fetching up to 10 videos...
⏳ Running Apify YouTube scraper...
✅ Successfully scraped 10 videos
📝 Creating transcript files...
✓ Created: 001_Video_Title_One.txt
✓ Created: 002_Video_Title_Two.txt
...
✅ Created 10 transcript files
☁️ Uploading files to Gemini File Search...
⬆️ Uploading: 001_Video_Title_One.txt
⬆️ Uploading: 002_Video_Title_Two.txt
...
✅ Uploaded 10 files to Gemini
================================================================================
💬 Chat Interface - Channel Name
================================================================================
Ask questions about the video transcripts!
Type 'quit' or 'exit' to end the conversation
🧑 You: What topics are covered in these videos?
🤖 Assistant: Based on the transcripts, the main topics include...
- Scraping: Uses Apify's YouTube scraper to fetch video metadata and transcripts
- File Creation: Creates individual text files for each video with title, description, and transcript
- Upload: Uploads all transcript files to Gemini's File Search for semantic indexing
- Chat: Provides an interactive chat interface powered by Gemini 2.0 with file search capabilities
gemini-api-rag/
├── youtube_rag.py # Main application script
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .env # Your API keys (not committed)
├── .gitignore # Git ignore rules
├── README.md # This file
├── CLAUDE.md # Project instructions
└── transcripts/ # Generated transcript files (not committed)
├── 001_video.txt
├── 002_video.txt
└── ...
- Gemini File Search: https://ai.google.dev/gemini-api/docs/file-search
- Apify Documentation: https://docs.apify.com/
- YouTube Scraper Actor: https://apify.com/streamers/youtube-scraper
- Free tier: 1 GB storage limit
- File size limit: 100 MB per file
- Embedding indexing: $0.15 per 1M tokens
- Queries and storage are free
- Free tier available with limited usage
- Check Apify pricing for details
Some videos may not have subtitles or transcripts available. The tool will still create files for these videos but with limited content.
If you encounter rate limit errors, try:
- Processing fewer videos at once
- Adding delays between requests
- Checking your API quotas
Ensure you have a stable internet connection and valid API keys.
Feel free to open issues or submit pull requests for improvements!
MIT License - feel free to use this tool for your projects!
- Built with Google Gemini API
- YouTube scraping powered by Apify