File size: 3,928 Bytes
e2f265f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""
Script to upload VidChain project to Hugging Face Hub
"""

import os
from huggingface_hub import login, create_repo, HfApi
from pathlib import Path

def upload_to_huggingface():
    # Step 1: Login to Hugging Face
    print("🔐 Logging in to Hugging Face Hub...")
    login()  # This will prompt for your token if not already logged in
    
    # Step 2: Configuration
    repo_id = "simplecloud/VidChain-exercise"  # Change this to your desired repo name
    repo_type = "dataset"  # Can be "space", "dataset", or "model"
    
    # Step 3: Create repository if it doesn't exist
    print(f"📦 Creating repository: {repo_id}")
    try:
        create_repo(
            repo_id=repo_id,
            repo_type=repo_type,
            exist_ok=True,
            private=False  # Set to True if you want a private repo
        )
        print(f"✅ Repository created/verified: {repo_id}")
    except Exception as e:
        print(f"⚠️ Repository creation issue: {e}")
    
    # Step 4: Initialize HfApi
    api = HfApi()
    
    # Step 5: Upload the entire project folder
    print("📤 Uploading project files...")
    current_dir = Path(".")
    
    # Define files/folders to upload
    files_to_upload = [
        "upload.py",
        ".gitignore",
        "asset/",
        "VTimeLLM/"
    ]
    
    # Upload each file/folder
    for item in files_to_upload:
        item_path = current_dir / item
        if item_path.exists():
            if item_path.is_file():
                print(f"📄 Uploading file: {item}")
                try:
                    api.upload_file(
                        path_or_fileobj=str(item_path),
                        path_in_repo=item,
                        repo_id=repo_id,
                        repo_type=repo_type
                    )
                    print(f"✅ Successfully uploaded: {item}")
                except Exception as e:
                    print(f"❌ Failed to upload {item}: {e}")
            else:
                print(f"📁 Uploading folder: {item}")
                try:
                    api.upload_folder(
                        folder_path=str(item_path),
                        path_in_repo=item,
                        repo_id=repo_id,
                        repo_type=repo_type,
                        ignore_patterns=["__pycache__", "*.pyc", ".DS_Store", ".git", ".ipynb"]
                    )
                    print(f"✅ Successfully uploaded: {item}")
                except Exception as e:
                    print(f"❌ Failed to upload {item}: {e}")
        else:
            print(f"⚠️ Skipping {item} - not found")
    
    # Step 6: Upload README.md separately (if it exists)
    readme_path = current_dir / "README.md"
    if readme_path.exists():
        print("📄 Uploading README.md...")
        try:
            api.upload_file(
                path_or_fileobj=str(readme_path),
                path_in_repo="README.md",
                repo_id=repo_id,
                repo_type=repo_type
            )
            print("✅ Successfully uploaded: README.md")
        except Exception as e:
            print(f"❌ Failed to upload README.md: {e}")
    
    # Step 7: Upload requirements.txt if it exists
    req_path = current_dir / "requirements.txt"
    if req_path.exists():
        print("📄 Uploading requirements.txt...")
        try:
            api.upload_file(
                path_or_fileobj=str(req_path),
                path_in_repo="requirements.txt",
                repo_id=repo_id,
                repo_type=repo_type
            )
            print("✅ Successfully uploaded: requirements.txt")
        except Exception as e:
            print(f"❌ Failed to upload requirements.txt: {e}")
    
    print(f"🎉 Upload completed! Your project is available at: https://huggingface.co/{repo_id}")

if __name__ == "__main__":
    upload_to_huggingface()