NimaKL commited on
Commit
e89f25d
·
verified ·
1 Parent(s): 0f9515d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -63,7 +63,10 @@ def get_similar_and_recommend(input_text):
63
  most_similar_index = np.argmax(similarities)
64
 
65
  # Get all features of the most similar video
66
- most_similar_video_features = df.iloc[most_similar_index].to_dict()
 
 
 
67
 
68
  # Recommend the top 10 videos based on GNN embeddings and dot product
69
  def recommend_next_10_videos(given_video_index, all_video_embeddings):
@@ -73,14 +76,20 @@ def get_similar_and_recommend(input_text):
73
  ]
74
  dot_products[given_video_index] = -float("inf")
75
 
76
- top_10_indices = np.argsort(dot_products)[::-1][:10]
77
  return [df.iloc[idx].to_dict() for idx in top_10_indices]
78
 
79
  top_10_recommended_videos_features = recommend_next_10_videos(
80
  most_similar_index, all_video_embeddings
81
  )
82
 
83
- # Create the output JSON with all features
 
 
 
 
 
 
84
  output = {
85
  "most_similar_video": most_similar_video_features,
86
  "top_10_recommended_videos": top_10_recommended_videos_features,
@@ -88,13 +97,13 @@ def get_similar_and_recommend(input_text):
88
 
89
  return output
90
 
91
- # Update the Gradio interface to output a JSON object containing all features
92
  interface = gr.Interface(
93
  fn=get_similar_and_recommend,
94
  inputs=gr.components.Textbox(label="Enter Text to Find Most Similar Video"),
95
  outputs=gr.JSON(),
96
  title="Video Recommendation System with GNN-based Recommendations",
97
- description="Enter text to find the most similar video and get the top 10 recommended videos with all features in a JSON object.",
98
  )
99
 
100
  interface.launch()
 
63
  most_similar_index = np.argmax(similarities)
64
 
65
  # Get all features of the most similar video
66
+ unwanted_keys = ["text_for_embedding", "embeddings"]
67
+ for key in unwanted_keys:
68
+ if key in most_similar_video_features:
69
+ del most_similar_video_features[key]
70
 
71
  # Recommend the top 10 videos based on GNN embeddings and dot product
72
  def recommend_next_10_videos(given_video_index, all_video_embeddings):
 
76
  ]
77
  dot_products[given_video_index] = -float("inf")
78
 
79
+ top_10_indices = np.argsort(dot_products)[[::-1][:10]
80
  return [df.iloc[idx].to_dict() for idx in top_10_indices]
81
 
82
  top_10_recommended_videos_features = recommend_next_10_videos(
83
  most_similar_index, all_video_embeddings
84
  )
85
 
86
+ # Exclude unwanted features for recommended videos
87
+ for recommended_video in top_10_recommended_videos_features:
88
+ for key in unwanted_keys:
89
+ if key in recommended_video:
90
+ del recommended_video[key]
91
+
92
+ # Create the output JSON with all features except the unwanted ones
93
  output = {
94
  "most_similar_video": most_similar_video_features,
95
  "top_10_recommended_videos": top_10_recommended_videos_features,
 
97
 
98
  return output
99
 
100
+ # Update the Gradio interface to output a JSON object without unwanted features
101
  interface = gr.Interface(
102
  fn=get_similar_and_recommend,
103
  inputs=gr.components.Textbox(label="Enter Text to Find Most Similar Video"),
104
  outputs=gr.JSON(),
105
  title="Video Recommendation System with GNN-based Recommendations",
106
+ description="Enter text to find the most similar video and get the top 10 recommended videos with all features except embeddings-related fields in a JSON object.",
107
  )
108
 
109
  interface.launch()