File size: 1,568 Bytes
1b5c2a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from huggingface_hub import HfApi, login
import os
import time
import sys

def upload_to_huggingface(repo_name, wait_minutes):
    # Convert minutes to seconds and wait
    print(f"Script will upload files in {wait_minutes} minutes...")
    time.sleep(wait_minutes * 60)
    
    # Initialize Hugging Face API
    api = HfApi()
    
    try:
        # Authenticate using your Hugging Face API token
        hf_token = os.getenv("HF_API_TOKEN")
        if not hf_token:
            raise ValueError("Hugging Face API token is not set. Please set it in the environment variable 'HF_API_TOKEN'.")
        login(token=hf_token)
        
        api.create_repo(repo_id=repo_name, private=True, exist_ok=True)

        # Get current directory
        current_dir = os.getcwd()
        
        print("Starting upload to Hugging Face...")
        
        # Upload all files from current directory
        api.upload_folder(
            folder_path=current_dir,
            repo_id=repo_name,
            repo_type="model"  
        )
        
        print("Upload completed successfully!")
        
    except Exception as e:
        print(f"An error occurred: {str(e)}")

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python script.py <repository_name> <minutes_to_wait>")
        print("Example: python script.py 'your-username/model-name' 120")
        sys.exit(1)
    
    repo_name = sys.argv[1]
    wait_minutes = int(sys.argv[2])
    
    upload_to_huggingface(repo_name, wait_minutes)