Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +3 -15
src/streamlit_app.py
CHANGED
|
@@ -4,29 +4,17 @@ import numpy as np
|
|
| 4 |
import tensorflow as tf
|
| 5 |
import joblib
|
| 6 |
import os
|
| 7 |
-
import zipfile
|
| 8 |
-
import tempfile
|
| 9 |
|
| 10 |
-
# Define
|
| 11 |
BASE_DIR = os.path.dirname(__file__)
|
| 12 |
-
|
| 13 |
MOVIES_PATH = os.path.join(BASE_DIR, "movies.csv")
|
| 14 |
ENCODINGS_PATH = os.path.join(BASE_DIR, "encodings.pkl")
|
| 15 |
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
extract_dir = os.path.join(tempfile.gettempdir(), "recommender_model_extracted")
|
| 21 |
-
|
| 22 |
-
# Only extract if not already done
|
| 23 |
-
if not os.path.exists(extract_dir):
|
| 24 |
-
with zipfile.ZipFile(ZIP_MODEL_PATH, "r") as zip_ref:
|
| 25 |
-
zip_ref.extractall(extract_dir)
|
| 26 |
-
|
| 27 |
-
# Load model from extracted directory
|
| 28 |
-
return tf.keras.models.load_model(extract_dir)
|
| 29 |
-
|
| 30 |
except Exception as e:
|
| 31 |
st.error(f"❌ Failed to load model:\n\n{e}")
|
| 32 |
st.stop()
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
import joblib
|
| 6 |
import os
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Define file paths
|
| 9 |
BASE_DIR = os.path.dirname(__file__)
|
| 10 |
+
KERAS_MODEL_PATH = os.path.join(BASE_DIR, "recommender_model.keras")
|
| 11 |
MOVIES_PATH = os.path.join(BASE_DIR, "movies.csv")
|
| 12 |
ENCODINGS_PATH = os.path.join(BASE_DIR, "encodings.pkl")
|
| 13 |
|
| 14 |
@st.cache_resource
|
| 15 |
def load_model():
|
| 16 |
try:
|
| 17 |
+
return tf.keras.models.load_model(KERAS_MODEL_PATH)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
st.error(f"❌ Failed to load model:\n\n{e}")
|
| 20 |
st.stop()
|