Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ merged_data = ratings.merge(books)
|
|
| 14 |
|
| 15 |
print(merged_data.columns)
|
| 16 |
|
| 17 |
-
dls = CollabDataLoaders.from_df(ratings, item_name='
|
| 18 |
|
| 19 |
class CollabNN(Module):
|
| 20 |
def __init__(self, user_sz, item_sz, y_range=(0,10.5), n_act=150):
|
|
@@ -59,7 +59,7 @@ print("Loaded Both")
|
|
| 59 |
|
| 60 |
# Function to get top N recommendations for a user using the Dot Product Model
|
| 61 |
def get_top_recommendations_dot(user_id, dls, n=3):
|
| 62 |
-
item_ids = dls.classes['
|
| 63 |
user_ids = [user_id] * len(item_ids)
|
| 64 |
user_item_pairs = torch.tensor(list(zip(user_ids, item_ids))).to(learn_dot.model.device)
|
| 65 |
predictions_dot = learn_dot.model(user_item_pairs).squeeze().tolist()
|
|
@@ -69,12 +69,12 @@ def get_top_recommendations_dot(user_id, dls, n=3):
|
|
| 69 |
|
| 70 |
# Function to get top N recommendations for a user using the CollabNN Model
|
| 71 |
def get_top_recommendations_nn(user_id, n=3):
|
| 72 |
-
item_ids = dls.classes['
|
| 73 |
user_ids = [user_id] * len(item_ids)
|
| 74 |
user_item_pairs = torch.tensor(list(zip(user_ids, item_ids))).to(deep_learner.model.device)
|
| 75 |
predictions_nn = deep_learner.model(user_item_pairs).squeeze().tolist()
|
| 76 |
top_indices = sorted(range(len(predictions_nn)), key=lambda i: predictions_nn[i], reverse=True)[:n]
|
| 77 |
-
top_recommendations = [dls.classes['
|
| 78 |
return top_recommendations
|
| 79 |
|
| 80 |
# Create a Gradio interface
|
|
|
|
| 14 |
|
| 15 |
print(merged_data.columns)
|
| 16 |
|
| 17 |
+
dls = CollabDataLoaders.from_df(ratings, item_name='title', bs=8192)
|
| 18 |
|
| 19 |
class CollabNN(Module):
|
| 20 |
def __init__(self, user_sz, item_sz, y_range=(0,10.5), n_act=150):
|
|
|
|
| 59 |
|
| 60 |
# Function to get top N recommendations for a user using the Dot Product Model
|
| 61 |
def get_top_recommendations_dot(user_id, dls, n=3):
|
| 62 |
+
item_ids = dls.classes['title'].o2i[ratings['title']]
|
| 63 |
user_ids = [user_id] * len(item_ids)
|
| 64 |
user_item_pairs = torch.tensor(list(zip(user_ids, item_ids))).to(learn_dot.model.device)
|
| 65 |
predictions_dot = learn_dot.model(user_item_pairs).squeeze().tolist()
|
|
|
|
| 69 |
|
| 70 |
# Function to get top N recommendations for a user using the CollabNN Model
|
| 71 |
def get_top_recommendations_nn(user_id, n=3):
|
| 72 |
+
item_ids = dls.classes['title'].o2i[ratings['title']]
|
| 73 |
user_ids = [user_id] * len(item_ids)
|
| 74 |
user_item_pairs = torch.tensor(list(zip(user_ids, item_ids))).to(deep_learner.model.device)
|
| 75 |
predictions_nn = deep_learner.model(user_item_pairs).squeeze().tolist()
|
| 76 |
top_indices = sorted(range(len(predictions_nn)), key=lambda i: predictions_nn[i], reverse=True)[:n]
|
| 77 |
+
top_recommendations = [dls.classes['title'].i2o[item_id] for item_id in top_indices]
|
| 78 |
return top_recommendations
|
| 79 |
|
| 80 |
# Create a Gradio interface
|