Robys01 commited on
Commit
724bf81
Β·
1 Parent(s): 6492f9e

Hope this works

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -1,29 +1,30 @@
1
  import os
2
  import pathlib
3
 
4
- # Hugging Face Hub cache β†’ /tmp
5
  os.environ["HF_HOME"] = "/tmp/huggingface"
6
  os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface"
7
-
8
- # XDG cache (for any other libraries) β†’ /tmp
9
  os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
10
 
11
- # Gradio general cache and examples cache β†’ /tmp
12
  os.environ["GRADIO_CACHE_DIR"] = "/tmp/.gradio"
13
  os.environ["GRADIO_EXAMPLES_CACHE"] = "/tmp/.gradio/cached_examples"
14
 
15
- # Pre-create all those directories so no one falls back to ./ .gradio or model/
16
- for d in [
17
  "/tmp/huggingface",
18
  "/tmp/.cache",
19
  "/tmp/.gradio",
20
  os.environ["GRADIO_EXAMPLES_CACHE"],
21
- ]:
22
  pathlib.Path(d).mkdir(parents=True, exist_ok=True)
23
 
 
24
  MODEL_DIR = "/tmp/model"
25
  pathlib.Path(MODEL_DIR).mkdir(parents=True, exist_ok=True)
 
26
 
 
27
  import time
28
  import torch
29
  from models import UNet
@@ -35,6 +36,7 @@ from huggingface_hub import hf_hub_download
35
  import tempfile
36
  import requests
37
 
 
38
  # Path to your downloaded model
39
  MODEL_PATH = os.path.join(MODEL_DIR, "best_unet_model.pth")
40
  # Download model if missing
 
1
  import os
2
  import pathlib
3
 
4
+ # ─── Redirect Hugging Face & other caches into /tmp ────────────────────────
5
  os.environ["HF_HOME"] = "/tmp/huggingface"
6
  os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface"
 
 
7
  os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
8
 
9
+ # ─── Redirect Gradio’s caches (general + examples) into /tmp ──────────────
10
  os.environ["GRADIO_CACHE_DIR"] = "/tmp/.gradio"
11
  os.environ["GRADIO_EXAMPLES_CACHE"] = "/tmp/.gradio/cached_examples"
12
 
13
+ # ─── Pre-create all writable dirs so nothing falls back to ./ .gradio or ./model
14
+ for d in (
15
  "/tmp/huggingface",
16
  "/tmp/.cache",
17
  "/tmp/.gradio",
18
  os.environ["GRADIO_EXAMPLES_CACHE"],
19
+ ):
20
  pathlib.Path(d).mkdir(parents=True, exist_ok=True)
21
 
22
+ # ─── Your model directory under /tmp ───────────────────────────────────────
23
  MODEL_DIR = "/tmp/model"
24
  pathlib.Path(MODEL_DIR).mkdir(parents=True, exist_ok=True)
25
+ MODEL_PATH = os.path.join(MODEL_DIR, "best_unet_model.pth")
26
 
27
+ # ─── Now safely import everything else ────────────────────────────────────
28
  import time
29
  import torch
30
  from models import UNet
 
36
  import tempfile
37
  import requests
38
 
39
+
40
  # Path to your downloaded model
41
  MODEL_PATH = os.path.join(MODEL_DIR, "best_unet_model.pth")
42
  # Download model if missing