Skip to content

Commit da9e9af

Browse files
committed
Add README documenting enhanced Gemini fallback and project structure
1 parent 889950f commit da9e9af

1 file changed

Lines changed: 73 additions & 40 deletions

File tree

youtube-relevance-finder/README.md

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,92 @@
1-
# YouTube Relevance Finder with Gemini AI
1+
# YouTube Relevance Finder with Gemini AI (Enhanced Version)
22

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+
---
47

58
## 🔍 Features
69

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
1115

12-
## 🛠️ Setup
16+
---
1317

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
1919

20-
2. **Install dependencies**:
20+
This version introduces several improvements compared to the original source code:
2121

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.
2525

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.
2829

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
3336

34-
## 🚀 Usage
37+
- **Explicit documentation of limitations**
38+
Known API constraints and fallback behavior are documented to reflect
39+
real-world usage conditions.
3540

36-
Run the script:
41+
These changes make the project more robust and suitable for learning and experimentation.
3742

38-
```bash
39-
python your_script_name.py
40-
```
43+
---
4144

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
4346

44-
## 📄 Example Output
47+
### 1. Clone the repository
4548

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
5452

55-
## 📌 Notes
53+
2. Install dependencies
54+
pip install google-api-python-client google-generativeai
5655

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
5960

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)