Tantawi commited on
Commit
5b9fe2b
·
verified ·
1 Parent(s): 20ff104

Update app/model_loader.py

Browse files
Files changed (1) hide show
  1. app/model_loader.py +6 -4
app/model_loader.py CHANGED
@@ -3,20 +3,22 @@ import os
3
  import tensorflow as tf
4
  from huggingface_hub import hf_hub_download
5
 
6
- MODEL_PATH = "app/model/efficientnetv2s.h5"
 
 
7
  REPO_ID = "Miguel764/efficientnetv2s-skin-cancer-classifier"
8
  FILENAME = "efficientnetv2s.h5"
9
 
10
  def load_model():
11
  if not os.path.exists(MODEL_PATH):
12
  print("Model not found locally. Downloading from Hugging Face...")
13
- os.makedirs(os.path.dirname(MODEL_PATH), exist_ok=True)
14
  hf_hub_download(
15
  repo_id=REPO_ID,
16
  filename=FILENAME,
17
- local_dir="app/model"
18
  )
19
  else:
20
  print("Model already exists locally.")
21
 
22
- return tf.keras.models.load_model(MODEL_PATH)
 
3
  import tensorflow as tf
4
  from huggingface_hub import hf_hub_download
5
 
6
+ # Use /tmp instead of /app/tmp is always writable inside Docker containers
7
+ MODEL_DIR = "/tmp/model"
8
+ MODEL_PATH = os.path.join(MODEL_DIR, "efficientnetv2s.h5")
9
  REPO_ID = "Miguel764/efficientnetv2s-skin-cancer-classifier"
10
  FILENAME = "efficientnetv2s.h5"
11
 
12
  def load_model():
13
  if not os.path.exists(MODEL_PATH):
14
  print("Model not found locally. Downloading from Hugging Face...")
15
+ os.makedirs(MODEL_DIR, exist_ok=True)
16
  hf_hub_download(
17
  repo_id=REPO_ID,
18
  filename=FILENAME,
19
+ local_dir=MODEL_DIR
20
  )
21
  else:
22
  print("Model already exists locally.")
23
 
24
+ return tf.keras.models.load_model(MODEL_PATH)