-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (44 loc) · 2.1 KB
/
main.py
File metadata and controls
51 lines (44 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from youtube_api import fetch_video_details
from scoring_modules import score_description, score_title, score_tags, score_category
from data_manager import save_feedback, load_feedback
from model_trainer import train_and_save_model, load_model
import numpy as np
MIN_FEEDBACK = 5
def main():
video_id = input('Enter YouTube video ID: ').strip()
goal = input('Enter your learning goal: ').strip()
details = fetch_video_details(video_id)
if not details:
print('Could not fetch video details.')
return
print(f"Title: {details['title']}")
print(f"Category: {details['category']}")
print(f"Tags: {', '.join(details['tags']) if details['tags'] else '(none)'}")
print(f"Description: {details['description'][:120]}{'...' if len(details['description']) > 120 else ''}")
# Compute scores
desc_score = score_description(goal, details['title'], details['description'])
title_score = score_title(goal, details['title'])
tags_score = score_tags(goal, details['tags'])
category_score = score_category(goal, details['category'])
features = np.array([[desc_score, title_score, tags_score, category_score]])
# Predict final score
model = load_model()
if model:
final_score = float(model.predict(features)[0])
else:
final_score = np.mean(features)
print(f"Predicted relevance score: {final_score:.2f} (0-1 scale)")
# User feedback
user_score = float(input('How would you rate this video for your goal? (0-1): '))
save_feedback(desc_score, title_score, tags_score, category_score, user_score)
# Retrain if enough feedback
feedback = load_feedback()
if len(feedback) >= MIN_FEEDBACK:
X = np.array([[float(row['desc_score']), float(row['title_score']), float(row['tags_score']), float(row['category_score'])] for row in feedback])
y = np.array([float(row['user_score']) for row in feedback])
train_and_save_model(X, y)
print('Model retrained with new feedback!')
else:
print(f'Not enough feedback to retrain (need {MIN_FEEDBACK}, have {len(feedback)})')
if __name__ == '__main__':
main()