karthikeya1212 commited on
Commit
32e7681
Β·
verified Β·
1 Parent(s): 94eb043

Update core/image_generator.py

Browse files
Files changed (1) hide show
  1. core/image_generator.py +17 -0
core/image_generator.py CHANGED
@@ -21,6 +21,8 @@ TMP_DIR = Path("/tmp/generated_images")
21
  for d in [HF_CACHE_DIR, MODEL_DIR, SEED_DIR, TMP_DIR]:
22
  d.mkdir(parents=True, exist_ok=True)
23
 
 
 
24
  os.environ.update({
25
  "HF_HOME": str(HF_CACHE_DIR),
26
  "HF_HUB_CACHE": str(HF_CACHE_DIR),
@@ -32,9 +34,24 @@ os.environ.update({
32
  "TMPDIR": str(HF_CACHE_DIR),
33
  "CACHE_DIR": str(HF_CACHE_DIR),
34
  })
 
 
35
  import tempfile
36
  tempfile.tempdir = str(HF_CACHE_DIR)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  print("[DEBUG] βœ… Using persistent Hugging Face cache at:", HF_CACHE_DIR)
40
  print("[DEBUG] βœ… Model directory:", MODEL_DIR)
 
21
  for d in [HF_CACHE_DIR, MODEL_DIR, SEED_DIR, TMP_DIR]:
22
  d.mkdir(parents=True, exist_ok=True)
23
 
24
+
25
+ # Ensure all relevant environment variables are correctly set
26
  os.environ.update({
27
  "HF_HOME": str(HF_CACHE_DIR),
28
  "HF_HUB_CACHE": str(HF_CACHE_DIR),
 
34
  "TMPDIR": str(HF_CACHE_DIR),
35
  "CACHE_DIR": str(HF_CACHE_DIR),
36
  })
37
+
38
+ # Force Python's tempfile to use /tmp/hf_cache too
39
  import tempfile
40
  tempfile.tempdir = str(HF_CACHE_DIR)
41
 
42
+ # πŸ”’ Extra layer: patch os.path.expanduser to block β€œ/.cache”
43
+ import os.path
44
+ def safe_expanduser(path):
45
+ if path.startswith("~") or path.startswith("/.cache"):
46
+ return str(HF_CACHE_DIR)
47
+ return os.path.expanduser_original(path)
48
+
49
+ os.path.expanduser_original = os.path.expanduser
50
+ os.path.expanduser = safe_expanduser
51
+
52
+ print("[DEBUG] βœ… Hugging Face and Diffusers cache fully redirected to:", HF_CACHE_DIR)
53
+
54
+
55
 
56
  print("[DEBUG] βœ… Using persistent Hugging Face cache at:", HF_CACHE_DIR)
57
  print("[DEBUG] βœ… Model directory:", MODEL_DIR)