File size: 2,161 Bytes
e59dc66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Script to upload the InternVL2 files to Hugging Face Spaces
"""

import os
import sys
import getpass
from huggingface_hub import HfApi, create_repo, upload_folder

# Default repository name
DEFAULT_REPO = "mknolan/cursor_slides_internvl2"

def main():
    """Main function to upload files to Hugging Face Spaces"""
    # Get Hugging Face token with WRITE access
    token = getpass.getpass("Enter your Hugging Face token (with WRITE access): ")
    
    # Get repository name
    repo_name = input("Enter repository name (default: {}): ".format(DEFAULT_REPO)) or DEFAULT_REPO
    
    print("Uploading to Space: {}".format(repo_name))
    
    # Initialize Hugging Face API
    api = HfApi(token=token)
    
    try:
        # Try to get the repository, create if it doesn't exist
        try:
            repo = api.repo_info(repo_id=repo_name, repo_type="space")
            print("Repo {} ready".format(repo_name))
        except Exception:
            print("Creating new Space: {}".format(repo_name))
            create_repo(
                repo_id=repo_name,
                token=token,
                repo_type="space",
                space_sdk="gradio",
                private=False
            )
        
        # Upload the entire folder at once using upload_folder
        print("Uploading files to Hugging Face Space...")
        upload_folder(
            folder_path=".",  # Current directory
            repo_id=repo_name,
            repo_type="space",
            ignore_patterns=[
                ".git*", 
                "*__pycache__*", 
                "*.pyc", 
                ".DS_Store", 
                "*.ipynb_checkpoints*",
                "venv",
                ".env"
            ],
            commit_message="Upload InternVL2 implementation",
            token=token
        )
        
        print("Upload completed!")
        print("Check your Space at: https://huggingface.co/spaces/{}".format(repo_name))
        
    except Exception as e:
        print("Error: {}".format(e))
        return 1
    
    return 0

if __name__ == "__main__":
    sys.exit(main())