Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import joblib
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import heapq
|
| 5 |
-
|
| 6 |
-
# Load saved artifacts
|
| 7 |
-
svd = joblib.load('svd_model.pkl')
|
| 8 |
-
movies = joblib.load('movies.pkl')
|
| 9 |
-
ratings = joblib.load('ratings.pkl')
|
| 10 |
-
|
| 11 |
-
def recommend_movies(user_id, N=10):
|
| 12 |
-
anti_testset = [(u, i, r) for (u, i, r) in ratings[['userId', 'movieId', 'rating']].itertuples(index=False) if u != user_id]
|
| 13 |
-
user_anti_testset = [t for t in anti_testset if t[0] == user_id][:1000] # Limit for speed
|
| 14 |
-
predictions = svd.test(user_anti_testset)
|
| 15 |
-
top_n = heapq.nlargest(N, predictions, key=lambda x: x.est)
|
| 16 |
-
top_movie_ids = [pred.iid for pred in top_n]
|
| 17 |
-
top_titles = movies[movies['movieId'].isin(top_movie_ids)]['title'].values
|
| 18 |
-
return "\n".join(top_titles)
|
| 19 |
-
|
| 20 |
-
demo = gr.Interface(
|
| 21 |
-
fn=recommend_movies,
|
| 22 |
-
inputs=[gr.Number(label="User ID", value=1), gr.Number(label="N", value=10)],
|
| 23 |
-
outputs="text",
|
| 24 |
-
title="Movie Recommendation System",
|
| 25 |
-
description="Enter a User ID and N to get top movie recommendations."
|
| 26 |
-
)
|
| 27 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|