diff --git a/src/controller/recommendationController.py b/src/controller/recommendationController.py index 89141ef..72892b9 100644 --- a/src/controller/recommendationController.py +++ b/src/controller/recommendationController.py @@ -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} diff --git a/src/recommendation_model/get_video_recommendation.py b/src/recommendation_model/get_video_recommendation.py index 5e83933..34f459b 100644 --- a/src/recommendation_model/get_video_recommendation.py +++ b/src/recommendation_model/get_video_recommendation.py @@ -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']) \ No newline at end of file + video_indices = [i[0] for i in sim_scores] + return list(df.iloc[video_indices][['ID']]['ID']) + except: + return 0 \ No newline at end of file