Skip to content

Commit

Permalink
correcao na recomendacao quando o video nao eh existente
Browse files Browse the repository at this point in the history
  • Loading branch information
victorleaoo committed Sep 1, 2024
1 parent 9b7ef41 commit 3280460
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/controller/recommendationController.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def get_recommendation_from_record(user_id: str =Query(...) , db: Session = Depe
# Gera lista de recomendações para cada vídeo no histórico
for video in videos_record:
videos_recommend = get_recommendations(int(video))
if videos_recommend == 0:
continue
recommendations.append(videos_recommend)
if videos_recommend: # Apenas adiciona recomendações se a lista não estiver vazia
recommendations.append(videos_recommend)

try:
for i in range(7):
Expand Down
5 changes: 4 additions & 1 deletion src/recommendation_model/get_video_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ def get_recommendations(id):

indices = pd.Series(df.index, index=df['ID']).drop_duplicates()

if id not in indices:
return []

try:
sim_scores = sorted(list(enumerate(cosine_sim[indices[id]])), key=lambda x: x[1], reverse=True)[
1:8] # Pega os 7 melhores
video_indices = [i[0] for i in sim_scores]
return list(df.iloc[video_indices][['ID']]['ID'])
except:
return 0
return []

0 comments on commit 3280460

Please sign in to comment.