Tantawi65 commited on
Commit
28241bd
·
1 Parent(s): 68aa285

Use existing local model instead of downloading from HuggingFace

Browse files
Files changed (2) hide show
  1. model_loader.py +8 -18
  2. requirements.txt +1 -2
model_loader.py CHANGED
@@ -1,25 +1,15 @@
1
  # model_loader.py
2
  import os
3
- import tempfile
4
  import tensorflow as tf
5
- from huggingface_hub import hf_hub_download
6
 
7
- # Use temporary directory for model storage
8
- TEMP_MODEL_DIR = tempfile.mkdtemp(prefix="model_")
9
- MODEL_PATH = os.path.join(TEMP_MODEL_DIR, "efficientnetv2s.h5")
10
- REPO_ID = "Miguel764/efficientnetv2s-skin-cancer-classifier"
11
- FILENAME = "efficientnetv2s.h5"
12
 
13
  def load_model():
14
  if not os.path.exists(MODEL_PATH):
15
- print("Model not found locally. Downloading from Hugging Face...")
16
- print(f"Using temporary model directory: {TEMP_MODEL_DIR}")
17
- hf_hub_download(
18
- repo_id=REPO_ID,
19
- filename=FILENAME,
20
- local_dir=TEMP_MODEL_DIR
21
- )
22
- else:
23
- print("Model already exists locally.")
24
-
25
- return tf.keras.models.load_model(MODEL_PATH)
 
1
  # model_loader.py
2
  import os
 
3
  import tensorflow as tf
 
4
 
5
+ # Use the existing local model file
6
+ MODEL_PATH = "model/efficientnetv2s.h5"
 
 
 
7
 
8
  def load_model():
9
  if not os.path.exists(MODEL_PATH):
10
+ raise FileNotFoundError(f"Model file not found at {MODEL_PATH}")
11
+
12
+ print(f"Loading model from: {MODEL_PATH}")
13
+ model = tf.keras.models.load_model(MODEL_PATH)
14
+ print("Model loaded successfully!")
15
+ return model
 
 
 
 
 
requirements.txt CHANGED
@@ -3,5 +3,4 @@ uvicorn[standard]
3
  python-multipart
4
  numpy
5
  Pillow
6
- tensorflow==2.10.0
7
- huggingface_hub
 
3
  python-multipart
4
  numpy
5
  Pillow
6
+ tensorflow==2.10.0