Skip to the content.

YouTube Relevance Finder with Gemini AI

This Python script searches YouTube for recent videos based on a user query and ranks them by relevance using Google’s Gemini AI model and Youtube API. It filters results by duration and recency, scores video titles for relevance, and returns the top-ranked videos.

🔍 Features

🛠️ Setup

  1. Clone the repository:
    git clone https://github.com/yourusername/your-repo-name.git
    cd your-repo-name
    
  2. Install dependencies:

    pip install google-api-python-client google-generativeai
    
  3. Set up environment variables: Create a .env file or export in terminal:

    export YT_API_KEY=your_youtube_api_key
    export GEMINI_API_KEY=your_gemini_api_key
    

🚀 Usage

Run the script:

python your_script_name.py

You’ll be prompted to enter a search query. The script will then display a list of the top relevant YouTube videos based on that query.

📄 Example Output

1. 
 • Title: Learn Python in 10 Minutes
 • URL: https://youtu.be/xyz123
 • Score: 9.2
 • Duration: 10m30s
 • Published: 2025-05-01T12:34:56Z

📌 Notes