|
1 | | -# YouTube Relevance Finder with Gemini AI |
| 1 | +# YouTube Relevance Finder with Gemini AI (Enhanced Version) |
2 | 2 |
|
3 | | -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. |
| 3 | +This Python application searches YouTube for recent videos based on a user query |
| 4 | +and ranks them by relevance using Google’s Gemini AI model and the YouTube Data API. |
| 5 | + |
| 6 | +--- |
4 | 7 |
|
5 | 8 | ## 🔍 Features |
6 | 9 |
|
7 | | -- Searches YouTube for videos from the past 14 days using Youtube API which is publicly available. |
8 | | -- Filters videos by duration (4–20 minutes) |
9 | | -- Uses Gemini AI to score title relevance to a query |
10 | | -- Prints the top relevant video links with scores and metadata |
| 10 | +- Searches YouTube for videos published within the last 14 days |
| 11 | +- Filters videos by duration (10–60 minutes) |
| 12 | +- Uses Gemini AI to score video title relevance to a search query |
| 13 | +- Gracefully falls back to a default score if Gemini API calls fail |
| 14 | +- Prints ranked video titles with relevance scores and publication dates |
11 | 15 |
|
12 | | -## 🛠️ Setup |
| 16 | +--- |
13 | 17 |
|
14 | | -1. **Clone the repository**: |
15 | | - ```bash |
16 | | - git clone https://github.com/yourusername/your-repo-name.git |
17 | | - cd your-repo-name |
18 | | -```` |
| 18 | +## 🆕 Differences from the Original Implementation |
19 | 19 |
|
20 | | -2. **Install dependencies**: |
| 20 | +This version introduces several improvements compared to the original source code: |
21 | 21 |
|
22 | | - ```bash |
23 | | - pip install google-api-python-client google-generativeai |
24 | | - ``` |
| 22 | +- **Graceful Gemini API fallback** |
| 23 | + When the Gemini API is unavailable, rate-limited, or returns an unexpected |
| 24 | + response, the application assigns a default relevance score instead of failing. |
25 | 25 |
|
26 | | -3. **Set up environment variables**: |
27 | | - Create a `.env` file or export in terminal: |
| 26 | +- **Cleaner error handling** |
| 27 | + SDK and API-related errors are handled internally and surfaced as clear, |
| 28 | + user-friendly warning messages. |
28 | 29 |
|
29 | | - ```bash |
30 | | - export YT_API_KEY=your_youtube_api_key |
31 | | - export GEMINI_API_KEY=your_gemini_api_key |
32 | | - ``` |
| 30 | +- **Improved project structure** |
| 31 | + The application logic is organized into dedicated classes for: |
| 32 | + - Time utilities |
| 33 | + - YouTube video extraction and filtering |
| 34 | + - Gemini-based scoring |
| 35 | + - Video ranking and processing |
33 | 36 |
|
34 | | -## 🚀 Usage |
| 37 | +- **Explicit documentation of limitations** |
| 38 | + Known API constraints and fallback behavior are documented to reflect |
| 39 | + real-world usage conditions. |
35 | 40 |
|
36 | | -Run the script: |
| 41 | +These changes make the project more robust and suitable for learning and experimentation. |
37 | 42 |
|
38 | | -```bash |
39 | | -python your_script_name.py |
40 | | -``` |
| 43 | +--- |
41 | 44 |
|
42 | | -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. |
| 45 | +## 🛠️ Setup |
43 | 46 |
|
44 | | -## 📄 Example Output |
| 47 | +### 1. Clone the repository |
45 | 48 |
|
46 | | -``` |
47 | | -1. |
48 | | - • Title: Learn Python in 10 Minutes |
49 | | - • URL: https://youtu.be/xyz123 |
50 | | - • Score: 9.2 |
51 | | - • Duration: 10m30s |
52 | | - • Published: 2025-05-01T12:34:56Z |
53 | | -``` |
| 49 | +```bash |
| 50 | +git clone https://github.com/yourusername/your-repo-name.git |
| 51 | +cd your-repo-name |
54 | 52 |
|
55 | | -## 📌 Notes |
| 53 | +2. Install dependencies |
| 54 | +pip install google-api-python-client google-generativeai |
56 | 55 |
|
57 | | -* Make sure you have valid API keys for both YouTube Data API v3 and Google Gemini. |
58 | | -* The script currently uses the `gemini-1.5-flash-latest` model. |
| 56 | +3. Set up environment variables |
| 57 | +Create a .env file or export in your terminal: |
| 58 | +export YT_API_KEY=your_youtube_api_key |
| 59 | +export GEMINI_API_KEY=your_gemini_api_key |
59 | 60 |
|
| 61 | +🚀 Usage |
| 62 | +Run the script: |
| 63 | +python app.py |
| 64 | + |
| 65 | +You will be prompted to enter a search query. |
| 66 | +The script will then display a list of the top relevant YouTube videos. |
| 67 | + |
| 68 | +📄 Example Output |
| 69 | +Enter your search: Brazilian Jiu Jitsu |
| 70 | +Filtered 5 videos based on criteria. |
| 71 | +[Warning] Gemini API call failed. Falling back to default relevance score. |
| 72 | + |
| 73 | +#1 |
| 74 | +Title: The New Face of Brazilian Jiu-Jitsu |
| 75 | +Score: 5.0 |
| 76 | +Published: 2026-01-08T16:16:56Z |
| 77 | + |
| 78 | +📌 Notes & Known Limitations |
| 79 | +Valid API keys are required for: |
| 80 | +YouTube Data API v3 |
| 81 | +Google Gemini API |
| 82 | +Gemini API usage is subject to quota limits and model availability |
| 83 | +When Gemini scoring fails, a default relevance score is applied so the |
| 84 | +application can continue running without interruption |
| 85 | +This fallback behavior is intentional and documented for learning purposes |
| 86 | + |
| 87 | +🎯 Purpose of This Project |
| 88 | +This project was contributed as part of an open-source learning journey to demonstrate: |
| 89 | +API integration with third-party services |
| 90 | +Defensive programming and graceful error handling |
| 91 | +Clean project organization and documentation |
| 92 | +Real-world constraints when working with LLM APIs |
0 commit comments