Spaces:
Runtime error
Runtime error
Tantawi65 commited on
Commit ·
68aa285
1
Parent(s): 2f34ba3
Fix: Use temporary directory for model storage to avoid permission issues
Browse files- Dockerfile +2 -1
- model_loader.py +6 -3
Dockerfile
CHANGED
|
@@ -4,7 +4,8 @@ FROM python:3.8
|
|
| 4 |
WORKDIR /code
|
| 5 |
|
| 6 |
# Create necessary directories with proper permissions
|
| 7 |
-
RUN mkdir -p /tmp/uploads
|
|
|
|
| 8 |
|
| 9 |
# Copy requirements first for better caching
|
| 10 |
COPY ./requirements.txt /code/requirements.txt
|
|
|
|
| 4 |
WORKDIR /code
|
| 5 |
|
| 6 |
# Create necessary directories with proper permissions
|
| 7 |
+
RUN mkdir -p /tmp/uploads /tmp/models && \
|
| 8 |
+
chmod 777 /tmp/uploads /tmp/models
|
| 9 |
|
| 10 |
# Copy requirements first for better caching
|
| 11 |
COPY ./requirements.txt /code/requirements.txt
|
model_loader.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
# model_loader.py
|
| 2 |
import os
|
|
|
|
| 3 |
import tensorflow as tf
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 14 |
hf_hub_download(
|
| 15 |
repo_id=REPO_ID,
|
| 16 |
filename=FILENAME,
|
| 17 |
-
local_dir=
|
| 18 |
)
|
| 19 |
else:
|
| 20 |
print("Model already exists locally.")
|
|
|
|
| 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.")
|