lenawilli commited on
Commit
58fac9f
·
verified ·
1 Parent(s): 29931a8

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 static file paths
11
  BASE_DIR = os.path.dirname(__file__)
12
- ZIP_MODEL_PATH = os.path.join(BASE_DIR, "recommender_model.zip")
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
- # Define extraction directory in a writable temp location
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()