Ahtaxam/RAG

โ˜… 0Forks 0PythonGitHub โ†—Compare

README

YouTube Transcript Bot ๐Ÿค–

A powerful AI-powered YouTube video transcript analyzer that allows you to ask questions about any YouTube video content. This bot extracts transcripts from YouTube videos, processes them using Google's Gemini AI, and provides intelligent answers to your questions based on the video content.

๐ŸŒŸ Features

  • Multi-language Support: Automatically detects and processes transcripts in English, Hindi, and Urdu
  • AI-Powered Q&A: Ask questions about video content and get intelligent answers
  • Transcript Cleaning: Automatically cleans and translates transcripts to fluent English
  • Vector Search: Uses FAISS vector database for efficient semantic search
  • RESTful API: FastAPI-based backend for easy integration
  • Chrome Extension Ready: Configured for Chrome extension integration

๐Ÿš€ How It Works

  1. Transcript Extraction: Fetches YouTube video transcripts using the YouTube Transcript API
  2. Language Processing: Cleans, corrects grammar, and translates non-English transcripts
  3. Vector Embedding: Converts processed text into vector embeddings using Google's embedding model
  4. Semantic Search: Uses FAISS vector database to find relevant content chunks
  5. AI Answering: Generates contextual answers using Google's Gemini 2.0 Flash model

๐Ÿ“‹ Prerequisites

  • Python 3.9+
  • Google API Key (for Gemini AI and embeddings)
  • YouTube video with available transcripts

๐Ÿ› ๏ธ Installation

  1. Clone the repository

    git clone https://github.com/Ahtaxam/RAG.git
    cd RAG
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variables Create a .env file in the root directory:

    GOOGLE_API_KEY=your_google_api_key_here
  4. Get Google API Key

๐Ÿš€ Usage

Running the API Server

python api.py

The server will start on http://localhost:5000

API Endpoints

GET /

  • Description: Health check endpoint
  • Response: {"message": "Hello World"}

POST /process

  • Description: Process a YouTube video and answer questions
  • Request Body:
    {
      "video_id": "W4tqbEmplug",
      "question": "What is the main topic of this video?"
    }
  • Response:
    {
      "success": true,
      "video_id": "W4tqbEmplug",
      "message": "Video processed successfully",
      "answer": "The main topic of this video is..."
    }

Example Usage

import requests

# Process a video and ask a question
response = requests.post("http://localhost:5000/process", json={
    "video_id": "W4tqbEmplug",
    "question": "What are the key points discussed in this video?"
})

print(response.json()["answer"])

๐Ÿ“ Project Structure

ytBot/
โ”œโ”€โ”€ api.py              # FastAPI server and endpoints
โ”œโ”€โ”€ load_transcript.py  # YouTube transcript extraction and processing
โ”œโ”€โ”€ index.py           # Vector database operations and Q&A logic
โ”œโ”€โ”€ requirements.txt   # Python dependencies
โ”œโ”€โ”€ .env              # Environment variables (create this)
โ””โ”€โ”€ README.md         # This file

๐Ÿ”ง Core Components

load_transcript.py

  • Extracts YouTube transcripts using youtube_transcript_api
  • Supports multiple languages (English, Hindi, Urdu)
  • Cleans and translates transcripts using Gemini AI
  • Handles errors for disabled transcripts or missing content

index.py

  • Converts transcripts to vector embeddings using Google's embedding model
  • Creates FAISS vector database for semantic search
  • Implements Q&A functionality using Gemini 2.0 Flash
  • Retrieves relevant context chunks for accurate answers

api.py

  • FastAPI server with CORS support for Chrome extension integration
  • RESTful endpoints for video processing and Q&A
  • Error handling and response formatting

๐ŸŒ Chrome Extension Integration

The API is configured to work with Chrome extensions:

  • CORS enabled for chrome-extension://* origins
  • Supports localhost development
  • Handles preflight OPTIONS requests

๐Ÿ” Supported Languages

The bot can process transcripts in:

  • English (en)
  • Hindi (hi)
  • Urdu (ur)

All transcripts are automatically translated to English for processing.

โš ๏ธ Limitations

  • Requires YouTube videos to have transcripts enabled
  • Depends on Google API quotas and rate limits
  • Video processing time depends on transcript length
  • Maximum context window for Gemini model

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ†˜ Troubleshooting

Common Issues

  1. "Transcripts are disabled": The YouTube video doesn't have transcripts available
  2. "No transcript found": Try a different video or check available languages
  3. API Key errors: Ensure your Google API key is valid and has the necessary permissions
  4. CORS errors: Check that your Chrome extension origin is properly configured

Getting Help

If you encounter issues:

  1. Check the console logs for detailed error messages
  2. Verify your API key is correctly set in the .env file
  3. Ensure the YouTube video has available transcripts
  4. Check your internet connection and API quotas

Made with โค๏ธ using FastAPI, LangChain, and Google Gemini AI

Contributors

Ahtaxam

Issues