Spaces:
Running
Running
Enhance Dockerfile and app.py for model directory permissions and download logging
Browse files- Dockerfile +2 -2
- app.py +4 -2
Dockerfile
CHANGED
|
@@ -28,8 +28,8 @@ WORKDIR /app
|
|
| 28 |
# Install runtime dependency: libopenblas.so.0 is provided by libopenblas-base.
|
| 29 |
RUN apt-get update && apt-get install -y build-essential cmake libopenblas-dev liblapack-dev libopenblas-dev liblapack-dev
|
| 30 |
|
| 31 |
-
# Create the "model"
|
| 32 |
-
RUN mkdir -p /app/model
|
| 33 |
|
| 34 |
COPY --from=builder /app/venv venv
|
| 35 |
|
|
|
|
| 28 |
# Install runtime dependency: libopenblas.so.0 is provided by libopenblas-base.
|
| 29 |
RUN apt-get update && apt-get install -y build-essential cmake libopenblas-dev liblapack-dev libopenblas-dev liblapack-dev
|
| 30 |
|
| 31 |
+
# Create the "model" directory with appropriate permissions
|
| 32 |
+
RUN mkdir -p /app/model && chmod -R 777 /app/model
|
| 33 |
|
| 34 |
COPY --from=builder /app/venv venv
|
| 35 |
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import torch
|
| 3 |
from models import UNet
|
| 4 |
from test_functions import process_image
|
|
@@ -12,13 +13,14 @@ MODEL_PATH = "model/best_unet_model.pth"
|
|
| 12 |
os.makedirs("model", exist_ok=True)
|
| 13 |
|
| 14 |
if not os.path.exists(MODEL_PATH):
|
| 15 |
-
print("
|
| 16 |
path = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth", local_dir="model", cache_dir="model")
|
| 17 |
-
print(
|
| 18 |
|
| 19 |
model = UNet()
|
| 20 |
model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))
|
| 21 |
model.eval()
|
|
|
|
| 22 |
|
| 23 |
def age_image(image: Image.Image, source_age: int, target_age: int) -> Image.Image:
|
| 24 |
# Ensure the image is in RGB or grayscale; if not, convert it.
|
|
|
|
| 1 |
import os
|
| 2 |
+
import time
|
| 3 |
import torch
|
| 4 |
from models import UNet
|
| 5 |
from test_functions import process_image
|
|
|
|
| 13 |
os.makedirs("model", exist_ok=True)
|
| 14 |
|
| 15 |
if not os.path.exists(MODEL_PATH):
|
| 16 |
+
print("Starting model download at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
| 17 |
path = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth", local_dir="model", cache_dir="model")
|
| 18 |
+
print("Model downloaded to", MODEL_PATH, "at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
| 19 |
|
| 20 |
model = UNet()
|
| 21 |
model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))
|
| 22 |
model.eval()
|
| 23 |
+
print("Model loaded at", time.strftime("%Y-%m-%d %H:%M:%S"))
|
| 24 |
|
| 25 |
def age_image(image: Image.Image, source_age: int, target_age: int) -> Image.Image:
|
| 26 |
# Ensure the image is in RGB or grayscale; if not, convert it.
|