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 ") 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)