debisoft commited on
Commit
4407ec2
·
1 Parent(s): 2d0c524
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -55,7 +55,7 @@ def greet(name, str2):
55
  user_df.drop("bio", axis=1, inplace=True)
56
  user_df = pd.concat([user_df, tfidf_df], axis=1)
57
 
58
- suggested_arr = recommend(user_df)
59
 
60
  return "Hello " + name + "!!" + " str2=" + str2
61
 
@@ -271,6 +271,27 @@ def recommend(user_df, num_recommendations=5):
271
  # Return the user_ids of the recommended users
272
  return tinder_df['username'].iloc[sim_indices]
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  # Setup complete!
275
 
276
  iface = gr.Interface(fn=greet, inputs=["text", "text"], outputs="text")
 
55
  user_df.drop("bio", axis=1, inplace=True)
56
  user_df = pd.concat([user_df, tfidf_df], axis=1)
57
 
58
+ suggested_arr = recommendOne(user_df)
59
 
60
  return "Hello " + name + "!!" + " str2=" + str2
61
 
 
271
  # Return the user_ids of the recommended users
272
  return tinder_df['username'].iloc[sim_indices]
273
 
274
+ def recommendOne(user_df, num_recommendations=1):
275
+
276
+ # Apply SVD to the feature
277
+ # matrix of the user_df dataframe
278
+ svd_matrixs = svd.transform(user_df)
279
+
280
+ # Calculate the cosine similarity
281
+ # between the user_df and training set users
282
+ cosine_sim_new = cosine_similarity(svd_matrixs, svd_matrix)
283
+
284
+ # Get the indices of the top
285
+ # num_recommendations similar users
286
+ sim_scores = list(enumerate(cosine_sim_new[0]))
287
+ sim_scores = sorted(sim_scores,
288
+ key=lambda x: x[1], reverse=True)
289
+ sim_indices = [i[0] for i in
290
+ sim_scores[1:num_recommendations+1]]
291
+ ser = tinder_df['username'].iloc[sim_indices]
292
+
293
+ return pd.Series(ser[sim_indices[0]])[0]
294
+
295
  # Setup complete!
296
 
297
  iface = gr.Interface(fn=greet, inputs=["text", "text"], outputs="text")