karthikeya1212 commited on
Commit
db1d80a
·
verified ·
1 Parent(s): 8f49d15

Update core/image_generator.py

Browse files
Files changed (1) hide show
  1. core/image_generator.py +22 -21
core/image_generator.py CHANGED
@@ -117,36 +117,37 @@
117
 
118
 
119
  # core/image_generator.py
 
120
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  import torch
122
  from diffusers import StableDiffusionXLPipeline
123
  from huggingface_hub import hf_hub_download
124
- from pathlib import Path
125
  from typing import List
126
  from io import BytesIO
127
  import base64
128
  from PIL import Image
129
 
130
- # ---------------- CACHE & MODEL DIRECTORIES ----------------
131
- HF_CACHE_DIR = Path("/tmp/hf_cache")
132
- MODEL_DIR = Path("/tmp/models/realvisxl_v4")
133
-
134
- # Create directories safely (no chmod)
135
- for d in [HF_CACHE_DIR, MODEL_DIR]:
136
- d.mkdir(parents=True, exist_ok=True)
137
-
138
- # Apply environment variables BEFORE any Hugging Face usage
139
- os.environ.update({
140
- "HF_HOME": str(HF_CACHE_DIR),
141
- "TRANSFORMERS_CACHE": str(HF_CACHE_DIR),
142
- "XDG_CACHE_HOME": str(HF_CACHE_DIR),
143
- "HF_DATASETS_CACHE": str(HF_CACHE_DIR),
144
- "HF_MODULES_CACHE": str(HF_CACHE_DIR),
145
- })
146
-
147
- # ---------------- MODEL CONFIG ----------------
148
- MODEL_REPO = "SG161222/RealVisXL_V4.0"
149
- MODEL_FILENAME = "RealVisXL_V4.0.safetensors"
150
 
151
  # ---------------- MODEL DOWNLOAD ----------------
152
  def download_model() -> Path:
 
117
 
118
 
119
  # core/image_generator.py
120
+ # ---------------- CACHE & MODEL DIRECTORIES (FIXED) ----------------
121
  import os
122
+ from pathlib import Path
123
+
124
+ # Force all Hugging Face caches to /tmp/hf_cache
125
+ HF_CACHE_DIR = Path("/tmp/hf_cache")
126
+ HF_CACHE_DIR.mkdir(parents=True, exist_ok=True)
127
+
128
+ MODEL_DIR = Path("/tmp/models/realvisxl_v4")
129
+ MODEL_DIR.mkdir(parents=True, exist_ok=True)
130
+
131
+ # MUST be set before importing diffusers/transformers
132
+ os.environ["HF_HOME"] = str(HF_CACHE_DIR)
133
+ os.environ["HF_HUB_CACHE"] = str(HF_CACHE_DIR)
134
+ os.environ["DIFFUSERS_CACHE"] = str(HF_CACHE_DIR)
135
+ os.environ["TRANSFORMERS_CACHE"] = str(HF_CACHE_DIR)
136
+ os.environ["XDG_CACHE_HOME"] = str(HF_CACHE_DIR)
137
+ os.environ["HF_DATASETS_CACHE"] = str(HF_CACHE_DIR)
138
+ os.environ["HF_MODULES_CACHE"] = str(HF_CACHE_DIR)
139
+
140
+ print("[DEBUG] Hugging Face cache directory set to:", HF_CACHE_DIR)
141
+ print("[DEBUG] Model directory set to:", MODEL_DIR)
142
+
143
  import torch
144
  from diffusers import StableDiffusionXLPipeline
145
  from huggingface_hub import hf_hub_download
 
146
  from typing import List
147
  from io import BytesIO
148
  import base64
149
  from PIL import Image
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  # ---------------- MODEL DOWNLOAD ----------------
153
  def download_model() -> Path: