Skip to content

Commit

Permalink
Ajuste no sistema de recomendacao
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRoger07 committed Aug 28, 2024
1 parent 81c0193 commit 3339557
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/controller/recommendationController.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ def get_recommendation_from_record(user_id: str =Query(...) , db: Session = Depe
try:
for i in range(7):
for list_recommendation in recommendations:
video = list_recommendation[i]

if len(final_recommendations) > 20:
break

if (str(video) not in videos_record) and (video not in final_recommendations):
final_recommendations.append(video)
try:
video = list_recommendation[i]
if len(final_recommendations) > 20:
break

if (str(video) not in videos_record) and (video not in final_recommendations):
final_recommendations.append(video)
except:
pass
except:
print("Não há vídeos recomendados suficientes!")
return {"recommend_videos": final_recommendations}
Expand Down
10 changes: 6 additions & 4 deletions src/recommendation_model/get_video_recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def get_recommendations(id):

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

sim_scores = sorted(list(enumerate(cosine_sim[indices[id]])), key=lambda x: x[1], reverse=True)[
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'])
video_indices = [i[0] for i in sim_scores]
return list(df.iloc[video_indices][['ID']]['ID'])
except:
return 0

0 comments on commit 3339557

Please sign in to comment.