AnimeOverlord commited on
Commit
114b4d9
·
1 Parent(s): 3e2ed1e

new update fix

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -655,7 +655,11 @@ HF_HUB_CACHE = os.path.join(HF_HOME, "hub")
655
  # Store the downloaded model files here
656
  MODEL_ROOT = os.path.join(SPACE_DATA_DIR, "models")
657
  MODEL_DIR = os.path.join(MODEL_ROOT, "FLUX.2-klein-4B")
658
- LORA_DIR = os.path.join(MODEL_ROOT, "flux2-klein-4b-mc")
 
 
 
 
659
 
660
  # Set these before any HF downloads happen
661
  os.environ["HF_HOME"] = HF_HOME
@@ -700,10 +704,8 @@ def _ensure_model_files():
700
  log_event("Checking model files...")
701
 
702
  os.makedirs(MODEL_DIR, exist_ok=True)
703
- os.makedirs(LORA_DIR, exist_ok=True)
704
 
705
  base_marker = os.path.join(MODEL_DIR, "model_index.json")
706
- lora_marker = os.path.join(LORA_DIR, "pytorch_lora_weights.safetensors")
707
 
708
  if not os.path.exists(base_marker):
709
  log_event(f"Downloading base model: {BASE_MODEL_ID}")
@@ -716,18 +718,21 @@ def _ensure_model_files():
716
  else:
717
  log_event(f"Base model already cached at {MODEL_DIR}")
718
 
719
- if not os.path.exists(lora_marker):
720
- log_event(f"Downloading LoRA: {LORA_ID}")
721
- snapshot_download(
722
- repo_id=LORA_ID,
723
- local_dir=LORA_DIR,
724
- local_dir_use_symlinks=False,
725
- allow_patterns=["pytorch_lora_weights.safetensors"],
726
- )
727
- log_event(f"LoRA downloaded to {LORA_DIR}")
728
- else:
729
- log_event(f"LoRA already cached at {LORA_DIR}")
730
-
 
 
 
731
 
732
  def _load_pipe():
733
  global _pipe, _pipe_ready
@@ -757,6 +762,9 @@ def _load_pipe():
757
 
758
  pipe.set_progress_bar_config(disable=False)
759
 
 
 
 
760
  _pipe = pipe
761
  _pipe_ready = True
762
  log_event("Pipeline ready")
 
655
  # Store the downloaded model files here
656
  MODEL_ROOT = os.path.join(SPACE_DATA_DIR, "models")
657
  MODEL_DIR = os.path.join(MODEL_ROOT, "FLUX.2-klein-4B")
658
+ import tempfile
659
+ import shutil
660
+
661
+ LORA_DIR = os.path.join(tempfile.gettempdir(), "flux2-klein-4b-mc-v2")
662
+ LORA_CACHE_DIR = os.path.join(tempfile.gettempdir(), "hf-lora-cache")
663
 
664
  # Set these before any HF downloads happen
665
  os.environ["HF_HOME"] = HF_HOME
 
704
  log_event("Checking model files...")
705
 
706
  os.makedirs(MODEL_DIR, exist_ok=True)
 
707
 
708
  base_marker = os.path.join(MODEL_DIR, "model_index.json")
 
709
 
710
  if not os.path.exists(base_marker):
711
  log_event(f"Downloading base model: {BASE_MODEL_ID}")
 
718
  else:
719
  log_event(f"Base model already cached at {MODEL_DIR}")
720
 
721
+ # Always refresh LoRA in temp storage
722
+ shutil.rmtree(LORA_DIR, ignore_errors=True)
723
+ shutil.rmtree(LORA_CACHE_DIR, ignore_errors=True)
724
+ os.makedirs(LORA_DIR, exist_ok=True)
725
+ os.makedirs(LORA_CACHE_DIR, exist_ok=True)
726
+
727
+ log_event(f"Downloading LoRA fresh to temp: {LORA_ID}")
728
+ snapshot_download(
729
+ repo_id=LORA_ID,
730
+ local_dir=LORA_DIR,
731
+ cache_dir=LORA_CACHE_DIR,
732
+ local_dir_use_symlinks=False,
733
+ allow_patterns=["pytorch_lora_weights.safetensors"],
734
+ )
735
+ log_event(f"LoRA downloaded to temp: {LORA_DIR}")
736
 
737
  def _load_pipe():
738
  global _pipe, _pipe_ready
 
762
 
763
  pipe.set_progress_bar_config(disable=False)
764
 
765
+ shutil.rmtree(LORA_DIR, ignore_errors=True)
766
+ shutil.rmtree(LORA_CACHE_DIR, ignore_errors=True)
767
+
768
  _pipe = pipe
769
  _pipe_ready = True
770
  log_event("Pipeline ready")