Jim Dowling commited on
Commit
a7ce432
โ€ข
1 Parent(s): a3a375e
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -48,7 +48,7 @@ def get_deployments():
48
  st.write('โœ… Deployments are ready!')
49
 
50
  # Returning deployment instances
51
- return interactions_fg, videos_fg, ranking_deployment, query_model_deployment, fs
52
 
53
  def insert_interaction(user_id, video_id, interactions_fg):
54
  generic = Generic(locale=Locale.EN)
@@ -67,7 +67,7 @@ def insert_interaction(user_id, video_id, interactions_fg):
67
  'watch_time': [watch_time]
68
  })
69
 
70
- interactions_fg.insert(interaction_df, write_options={"start_offline_materialization": False})
71
 
72
 
73
  # Define function to fetch recommendations
@@ -75,7 +75,6 @@ def fetch_recommendations(user_id, query_model_deployment):
75
  st.write('๐Ÿ”ฎ Getting recommendations...')
76
  deployment_input = {"instances": {"user_id": user_id}}
77
  prediction = query_model_deployment.predict(deployment_input)['predictions']['ranking']
78
- st.write('๐Ÿ”ฎ Got recommendations...')
79
  return prediction
80
 
81
  # Function to insert interaction and fetch new recommendations
@@ -83,12 +82,13 @@ def handle_interaction(user_id, video_id, interactions_fg, query_model_deploymen
83
  insert_interaction(user_id, video_id, interactions_fg)
84
  return fetch_recommendations(user_id, query_model_deployment)
85
 
 
86
  # Main Streamlit application logic
87
  def main():
88
  st.title('๐ŸŽฌ Video Recommender')
89
  # Initialize or re-use existing deployments
90
  if 'deployments_initialized' not in st.session_state:
91
- st.session_state.interactions_fg, st.session_state.videos_fg, st.session_state.ranking_deployment, st.session_state.query_model_deployment, st.session_state.fs = get_deployments()
92
  st.session_state['deployments_initialized'] = True
93
 
94
  # User selection box
@@ -107,27 +107,9 @@ def main():
107
 
108
  print_header('๐Ÿ“ Top 3 Recommendations:')
109
  displayed_recommendations = st.session_state.recommendations[:3]
110
-
111
- # Retrieve video information
112
- video_id_list = [{"video_id": video_id[1]} for video_id in displayed_recommendations]
113
- string_list = [f"'{i[1]}'" for i in displayed_recommendations]
114
- result_string = ",".join(string_list)
115
- sql_str = f"SELECT * FROM videos_1 WHERE video_id IN ({result_string})"
116
- print(sql_str)
117
- videos_df = st.session_state.fs.sql(sql_str, online=True)
118
- videos_info = videos_df.to_dict('records')
119
-
120
- for video_info in videos_info:
121
- video_id = video_info['video_id']
122
- category = video_info['category']
123
- likes = video_info['likes']
124
- upload_date = video_info['upload_date']
125
- video_length = video_info['video_length']
126
- views = video_info['views']
127
-
128
- # Button text with video information
129
- button_text = f"๐Ÿ”— Video ID: {video_id} | ๐ŸŽฅ Category: {category} | ๐Ÿ‘๐Ÿป Likes: {likes} | ๐Ÿ‘๏ธ Views: {views} | โš™๏ธ Length: {video_length}"
130
- if st.button(button_text, key=video_id):
131
  new_recommendations = handle_interaction(
132
  user_id_option,
133
  video_id,
 
48
  st.write('โœ… Deployments are ready!')
49
 
50
  # Returning deployment instances
51
+ return interactions_fg, videos_fg, ranking_deployment, query_model_deployment
52
 
53
  def insert_interaction(user_id, video_id, interactions_fg):
54
  generic = Generic(locale=Locale.EN)
 
67
  'watch_time': [watch_time]
68
  })
69
 
70
+ interactions_fg.insert(interaction_df)
71
 
72
 
73
  # Define function to fetch recommendations
 
75
  st.write('๐Ÿ”ฎ Getting recommendations...')
76
  deployment_input = {"instances": {"user_id": user_id}}
77
  prediction = query_model_deployment.predict(deployment_input)['predictions']['ranking']
 
78
  return prediction
79
 
80
  # Function to insert interaction and fetch new recommendations
 
82
  insert_interaction(user_id, video_id, interactions_fg)
83
  return fetch_recommendations(user_id, query_model_deployment)
84
 
85
+
86
  # Main Streamlit application logic
87
  def main():
88
  st.title('๐ŸŽฌ Video Recommender')
89
  # Initialize or re-use existing deployments
90
  if 'deployments_initialized' not in st.session_state:
91
+ st.session_state.interactions_fg, st.session_state.videos_fg, st.session_state.ranking_deployment, st.session_state.query_model_deployment = get_deployments()
92
  st.session_state['deployments_initialized'] = True
93
 
94
  # User selection box
 
107
 
108
  print_header('๐Ÿ“ Top 3 Recommendations:')
109
  displayed_recommendations = st.session_state.recommendations[:3]
110
+ for recommendation in displayed_recommendations:
111
+ video_id = recommendation[1]
112
+ if st.button(f"๐Ÿ”— Video ID: {video_id}", key=video_id):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  new_recommendations = handle_interaction(
114
  user_id_option,
115
  video_id,