# dl_local_fix.py
import os
from huggingface_hub import snapshot_download

# Force Online
if "HF_HUB_OFFLINE" in os.environ:
    del os.environ["HF_HUB_OFFLINE"]

def download_to_local_folder():
    print(f"===========================================================")
    print(f"DOWNLOADING TO LOCAL FOLDERS (The 'Nuclear Option')")
    print(f"Current Directory: {os.getcwd()}")
    print(f"===========================================================\n")

    # 1. ALIGN Fix: xlm-roberta-large
    # We download this into a folder named EXACTLY "xlm-roberta-large"
    print(">>> Downloading ALIGN dependencies to ./xlm-roberta-large/ ...")
    snapshot_download(
        repo_id="xlm-roberta-large",
        local_dir="./xlm-roberta-large",      # <--- Creates this folder
        local_dir_use_symlinks=False,         # <--- Real files, no symlinks
        ignore_patterns=["*.bin", "*.safetensors", "*.h5", "rust_model.ot"] # Light files only
    )
    print("DONE.\n")

    # 2. SigLIP Fix: timm/ViT-B-16-SigLIP
    # We download this into a folder named EXACTLY "timm/ViT-B-16-SigLIP"
    print(">>> Downloading SigLIP dependencies to ./timm/ViT-B-16-SigLIP/ ...")
    snapshot_download(
        repo_id="timm/ViT-B-16-SigLIP",
        local_dir="./timm/ViT-B-16-SigLIP",   # <--- Creates this folder structure
        local_dir_use_symlinks=False,
        ignore_patterns=["*.bin", "*.safetensors"]
    )
    print("DONE.\n")

    print("===========================================================")
    print("FIX COMPLETE.")
    print("You should now see a folder 'xlm-roberta-large' and 'timm' in your directory.")
    print("Re-submit your jobs. Transformers will find these folders and work.")
    print("===========================================================")

if __name__ == "__main__":
    download_to_local_folder()