Skip to content

Commit 83e5220

Browse files
authored
PR #64: Youtube Relevance Finder
Improve Gemini error handling and document fallback behaviorYoutube relevance finder Merge pull request #64 from asabo-dev/youtube-relevance-finder
2 parents 3023f4b + da9e9af commit 83e5220

4 files changed

Lines changed: 195 additions & 106 deletions

File tree

Youtube_video_finder_using_geminillm/README.md

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# macOS
2+
.DS_Store
3+
4+
# Environment variables
5+
.env
6+
.env.*
7+
8+
# Python
9+
__pycache__/
10+
*.py[cod]
11+
12+
# Virtual environments
13+
venv/
14+
.venv/
15+
16+
# IDEs
17+
.vscode/
18+
.idea/
19+
20+
# Logs
21+
*.log

youtube-relevance-finder/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# YouTube Relevance Finder with Gemini AI (Enhanced Version)
2+
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+
---
7+
8+
## 🔍 Features
9+
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
15+
16+
---
17+
18+
## 🆕 Differences from the Original Implementation
19+
20+
This version introduces several improvements compared to the original source code:
21+
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+
26+
- **Cleaner error handling**
27+
SDK and API-related errors are handled internally and surfaced as clear,
28+
user-friendly warning messages.
29+
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
36+
37+
- **Explicit documentation of limitations**
38+
Known API constraints and fallback behavior are documented to reflect
39+
real-world usage conditions.
40+
41+
These changes make the project more robust and suitable for learning and experimentation.
42+
43+
---
44+
45+
## 🛠️ Setup
46+
47+
### 1. Clone the repository
48+
49+
```bash
50+
git clone https://github.com/yourusername/your-repo-name.git
51+
cd your-repo-name
52+
53+
2. Install dependencies
54+
pip install google-api-python-client google-generativeai
55+
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
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

Comments
 (0)