Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,24 +39,24 @@ def get_recommendations(title, cosine_sim=cosine_sim):
|
|
39 |
# Sort the movies based on the similarity scores
|
40 |
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
41 |
|
42 |
-
# Get the scores of the
|
43 |
-
sim_scores = sim_scores[1:
|
44 |
|
45 |
# Get the movie indices
|
46 |
movie_indices = [i[0] for i in sim_scores]
|
47 |
|
48 |
-
# Return the top
|
49 |
recommendations = [(movies['title'].iloc[i], sim_scores[idx][1]) for idx, i in enumerate(movie_indices)]
|
50 |
return recommendations
|
51 |
|
52 |
# Gradio interface
|
53 |
def recommend_movies(movie):
|
54 |
recommendations = get_recommendations(movie)
|
55 |
-
return "\n".join([f"{title}: {score:.2f}" for title, score in recommendations])
|
56 |
|
57 |
# Create the Gradio interface
|
58 |
movie_list = movies['title'].tolist()
|
59 |
-
iface = gr.Interface(fn=recommend_movies, inputs=gr.Dropdown(movie_list), outputs="text", title="Movie Recommender", description="Select a movie to get recommendations based on content filtering.")
|
60 |
|
61 |
# Launch the app
|
62 |
iface.launch()
|
|
|
39 |
# Sort the movies based on the similarity scores
|
40 |
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)
|
41 |
|
42 |
+
# Get the scores of the 20 most similar movies
|
43 |
+
sim_scores = sim_scores[1:21]
|
44 |
|
45 |
# Get the movie indices
|
46 |
movie_indices = [i[0] for i in sim_scores]
|
47 |
|
48 |
+
# Return the top 20 most similar movies with their scores
|
49 |
recommendations = [(movies['title'].iloc[i], sim_scores[idx][1]) for idx, i in enumerate(movie_indices)]
|
50 |
return recommendations
|
51 |
|
52 |
# Gradio interface
|
53 |
def recommend_movies(movie):
|
54 |
recommendations = get_recommendations(movie)
|
55 |
+
return "\n".join([f"**{title}: {score:.2f}**" for title, score in recommendations])
|
56 |
|
57 |
# Create the Gradio interface
|
58 |
movie_list = movies['title'].tolist()
|
59 |
+
iface = gr.Interface(fn=recommend_movies, inputs=gr.Dropdown(movie_list), outputs="text", title="Movie Recommender - Content-Based Filtering", description="Select a movie to get recommendations based on content filtering.")
|
60 |
|
61 |
# Launch the app
|
62 |
iface.launch()
|