Spaces:
Runtime error
Runtime error
Jim Dowling
commited on
Commit
โข
a7ce432
1
Parent(s):
a3a375e
fix
Browse files
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
|
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
|
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
|
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 |
-
|
112 |
-
|
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,
|