Spaces:
Running
Running
Hope this works
Browse files
app.py
CHANGED
|
@@ -1,29 +1,30 @@
|
|
| 1 |
import os
|
| 2 |
import pathlib
|
| 3 |
|
| 4 |
-
# Hugging Face
|
| 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
|
| 12 |
os.environ["GRADIO_CACHE_DIR"] = "/tmp/.gradio"
|
| 13 |
os.environ["GRADIO_EXAMPLES_CACHE"] = "/tmp/.gradio/cached_examples"
|
| 14 |
|
| 15 |
-
# Pre-create all
|
| 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
|