Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -7
src/streamlit_app.py
CHANGED
|
@@ -23,14 +23,15 @@ from recommendation_utils import (
|
|
| 23 |
@st.cache_resource(show_spinner=False)
|
| 24 |
def download_models_once():
|
| 25 |
DOWNLOAD_DIR = "/tmp"
|
| 26 |
-
|
| 27 |
files = {
|
| 28 |
"encodings.pkl": "1EzpdpaopfUp-Tfc7YjxPVYQUwnU_BX5-",
|
| 29 |
-
"
|
|
|
|
| 30 |
"svd_model.pkl": "1fN2biQruVjJHHv2vX1g1hLuMeJoPqyFX",
|
| 31 |
"trainset.pkl": "1IDVVAQ57Xvf3HCAikbOSQgAigdHP7Ik7"
|
| 32 |
}
|
| 33 |
-
|
| 34 |
def gdrive_download(file_id, destination):
|
| 35 |
URL = "https://drive.google.com/uc?export=download"
|
| 36 |
session = requests.Session()
|
|
@@ -45,19 +46,18 @@ def download_models_once():
|
|
| 45 |
for chunk in response.iter_content(32768):
|
| 46 |
if chunk:
|
| 47 |
f.write(chunk)
|
| 48 |
-
|
| 49 |
for filename, file_id in files.items():
|
| 50 |
full_path = os.path.join(DOWNLOAD_DIR, filename)
|
| 51 |
if not os.path.exists(full_path):
|
| 52 |
with st.spinner(f"Downloading {filename}..."):
|
| 53 |
gdrive_download(file_id, full_path)
|
| 54 |
|
| 55 |
-
|
| 56 |
download_models_once()
|
| 57 |
|
| 58 |
@st.cache_resource
|
| 59 |
def load_models():
|
| 60 |
-
nn_model = load_nn_model("/tmp/
|
| 61 |
svd_model = load_svd_model("/tmp/svd_model.pkl")
|
| 62 |
trainset = load_trainset("/tmp/trainset.pkl")
|
| 63 |
return nn_model, svd_model, trainset
|
|
@@ -553,7 +553,7 @@ else:
|
|
| 553 |
if user_ratings_dict:
|
| 554 |
if st.session_state["model_selection"] == "Neural Network":
|
| 555 |
available_movies = movie_df["movieId"].tolist()
|
| 556 |
-
recommendations = recommend_with_nn(
|
| 557 |
|
| 558 |
else:
|
| 559 |
ratings_full = pd.DataFrame(all_ratings_data)
|
|
|
|
| 23 |
@st.cache_resource(show_spinner=False)
|
| 24 |
def download_models_once():
|
| 25 |
DOWNLOAD_DIR = "/tmp"
|
| 26 |
+
|
| 27 |
files = {
|
| 28 |
"encodings.pkl": "1EzpdpaopfUp-Tfc7YjxPVYQUwnU_BX5-",
|
| 29 |
+
"config.json": "1ZcTrVR0QtS-5EL4amsTR_y9xITDA6zlJ",
|
| 30 |
+
"model.weights.h5": "1VjjUx_7ulIVM-W1lqH-nDHI7HWfpcMQP",
|
| 31 |
"svd_model.pkl": "1fN2biQruVjJHHv2vX1g1hLuMeJoPqyFX",
|
| 32 |
"trainset.pkl": "1IDVVAQ57Xvf3HCAikbOSQgAigdHP7Ik7"
|
| 33 |
}
|
| 34 |
+
|
| 35 |
def gdrive_download(file_id, destination):
|
| 36 |
URL = "https://drive.google.com/uc?export=download"
|
| 37 |
session = requests.Session()
|
|
|
|
| 46 |
for chunk in response.iter_content(32768):
|
| 47 |
if chunk:
|
| 48 |
f.write(chunk)
|
| 49 |
+
|
| 50 |
for filename, file_id in files.items():
|
| 51 |
full_path = os.path.join(DOWNLOAD_DIR, filename)
|
| 52 |
if not os.path.exists(full_path):
|
| 53 |
with st.spinner(f"Downloading {filename}..."):
|
| 54 |
gdrive_download(file_id, full_path)
|
| 55 |
|
|
|
|
| 56 |
download_models_once()
|
| 57 |
|
| 58 |
@st.cache_resource
|
| 59 |
def load_models():
|
| 60 |
+
nn_model = load_nn_model("/tmp/config.json", "/tmp/model.weights.h5")
|
| 61 |
svd_model = load_svd_model("/tmp/svd_model.pkl")
|
| 62 |
trainset = load_trainset("/tmp/trainset.pkl")
|
| 63 |
return nn_model, svd_model, trainset
|
|
|
|
| 553 |
if user_ratings_dict:
|
| 554 |
if st.session_state["model_selection"] == "Neural Network":
|
| 555 |
available_movies = movie_df["movieId"].tolist()
|
| 556 |
+
recommendations = recommend_with_nn(user_ratings_dict, nn_model, encodings, top_n=10)
|
| 557 |
|
| 558 |
else:
|
| 559 |
ratings_full = pd.DataFrame(all_ratings_data)
|