Robys01 commited on
Commit
030a144
·
1 Parent(s): d82f080

Access to model directory

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. Dockerfile +3 -0
  3. app.py +8 -2
.gitignore CHANGED
@@ -3,3 +3,4 @@ venv
3
 
4
  __pycache__
5
 
 
 
3
 
4
  __pycache__
5
 
6
+ model
Dockerfile CHANGED
@@ -28,6 +28,9 @@ 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
  COPY --from=builder /app/venv venv
32
 
33
  COPY app.py .
 
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" folder for caching the model file
32
+ RUN mkdir -p /app/model
33
+
34
  COPY --from=builder /app/venv venv
35
 
36
  COPY app.py .
app.py CHANGED
@@ -7,8 +7,14 @@ import gradio as gr
7
 
8
  from huggingface_hub import hf_hub_download
9
 
10
- MODEL_PATH = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth")
11
- print(f"Model downloaded to {MODEL_PATH}")
 
 
 
 
 
 
12
 
13
  model = UNet()
14
  model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))
 
7
 
8
  from huggingface_hub import hf_hub_download
9
 
10
+ MODEL_PATH = "model/best_unet_model.pth"
11
+
12
+ os.makedirs("model", exist_ok=True)
13
+
14
+ if not os.path.exists(MODEL_PATH):
15
+ print("Downloading model from Hugging Face...")
16
+ path = hf_hub_download(repo_id="Robys01/face-aging", filename="best_unet_model.pth", local_dir="model", cache_dir="model")
17
+ print(f"Model downloaded to {path}")
18
 
19
  model = UNet()
20
  model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu"), weights_only=False))