File size: 2,690 Bytes
27a346a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
download_model.py - Utility script to download LionGuard2 model from Hugging Face
"""

import os
import argparse
from huggingface_hub import hf_hub_download


def download_lionguard2(repo_id, filename="LionGuard2.safetensors", token=None, output_dir="./"):
    """
    Download LionGuard2 model from Hugging Face private repository.
    
    Args:
        repo_id: The Hugging Face repository ID (e.g., "username/repo-name")
        filename: The filename to download (default: "LionGuard2.safetensors")
        token: Hugging Face access token for private repositories
        output_dir: Directory to save the downloaded file
    """
    if token is None:
        token = os.environ.get("HF_API_KEY")
        if not token:
            print("Error: No HF_API_KEY found in environment variables.")
            print("Please set your Hugging Face token:")
            print("export HF_API_KEY=your_token_here")
            return False
    
    try:
        print(f"Downloading {filename} from {repo_id}...")
        
        # Download the model file
        model_path = hf_hub_download(
            repo_id=repo_id,
            filename=filename,
            token=token,
            local_dir=output_dir,
            local_dir_use_symlinks=False  # Download actual file, not symlink
        )
        
        print(f"βœ… Model successfully downloaded to: {model_path}")
        return True
        
    except Exception as e:
        print(f"❌ Failed to download model: {e}")
        return False


def main():
    parser = argparse.ArgumentParser(description="Download LionGuard2 model from Hugging Face")
    parser.add_argument("repo_id", help="Hugging Face repository ID (e.g., username/repo-name)")
    parser.add_argument("--filename", default="LionGuard2.safetensors", help="Filename to download")
    parser.add_argument("--token", help="Hugging Face access token (optional if HF_API_KEY env var is set)")
    parser.add_argument("--output-dir", default="./", help="Output directory for downloaded file")
    
    args = parser.parse_args()
    
    success = download_lionguard2(
        repo_id=args.repo_id,
        filename=args.filename,
        token=args.token,
        output_dir=args.output_dir
    )
    
    if success:
        print(f"\nπŸŽ‰ Ready to use! The model has been downloaded and can now be used by the application.")
    else:
        print(f"\nπŸ’‘ Make sure you have:")
        print(f"   1. Valid Hugging Face token with access to the private repository")
        print(f"   2. Correct repository ID: {args.repo_id}")
        print(f"   3. The model file exists in the repository")


if __name__ == "__main__":
    main()