Robys01 commited on
Commit
c7fd97b
Β·
1 Parent(s): 724bf81
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -1,16 +1,23 @@
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",
@@ -19,27 +26,12 @@ for d in (
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
31
- from test_functions import process_image
32
- from PIL import Image
33
- import gradio as gr
34
- from gradio_client import Client, handle_file
35
- from huggingface_hub import hf_hub_download
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
43
  def download_model():
44
  print("Starting model download at", time.strftime("%Y-%m-%d %H:%M:%S"))
45
  path = hf_hub_download(
 
1
  import os
2
  import pathlib
3
+ import time
4
+ import torch
5
+ from models import UNet
6
+ from test_functions import process_image
7
+ from PIL import Image
8
+ import gradio as gr
9
+ from gradio_client import Client, handle_file
10
+ from huggingface_hub import hf_hub_download
11
+ import tempfile
12
+ import requests
13
 
 
14
  os.environ["HF_HOME"] = "/tmp/huggingface"
15
  os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface"
16
  os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
17
 
 
18
  os.environ["GRADIO_CACHE_DIR"] = "/tmp/.gradio"
19
  os.environ["GRADIO_EXAMPLES_CACHE"] = "/tmp/.gradio/cached_examples"
20
 
 
21
  for d in (
22
  "/tmp/huggingface",
23
  "/tmp/.cache",
 
26
  ):
27
  pathlib.Path(d).mkdir(parents=True, exist_ok=True)
28
 
 
29
  MODEL_DIR = "/tmp/model"
30
  pathlib.Path(MODEL_DIR).mkdir(parents=True, exist_ok=True)
31
  MODEL_PATH = os.path.join(MODEL_DIR, "best_unet_model.pth")
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
 
34
  MODEL_PATH = os.path.join(MODEL_DIR, "best_unet_model.pth")
 
35
  def download_model():
36
  print("Starting model download at", time.strftime("%Y-%m-%d %H:%M:%S"))
37
  path = hf_hub_download(