File size: 1,976 Bytes
28c5847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Upload Stock Market BPE Tokenizer to HuggingFace

"""

import os
from huggingface_hub import HfApi, create_repo, login

# Configuration
print("="*50)
print("HuggingFace Uploader")
print("="*50)

# 1. Login
print("\nPlease enter your HuggingFace Write Token.")
print("(Get it from: https://huggingface.co/settings/tokens)")
token = input("Token: ").strip()

try:
    login(token=token)
    print("βœ“ Login successful!")
except Exception as e:
    print(f"❌ Login failed: {e}")
    exit(1)

# 2. Get Username
api = HfApi()
user_info = api.whoami()
username = user_info['name']
print(f"Logged in as: {username}")

# 3. Repository Config
MODEL_NAME = "stock-market-bpe-tokenizer"
REPO_ID = f"{username}/{MODEL_NAME}"

print(f"\nPreparing to upload to {REPO_ID}...")

try:
    # 4. Create Repository (if it doesn't exist)
    print("Creating repository...")
    create_repo(repo_id=REPO_ID, repo_type="model", exist_ok=True)
    
    # 5. Upload Files
    files_to_upload = [
        "stock_bpe.merges",
        "stock_bpe.vocab",
        "tokenizer.py",
        "README.md",
        "example_usage.ipynb",
        "requirements.txt",
        "app.py"
    ]
    
    print("\nUploading files...")
    for file in files_to_upload:
        if os.path.exists(file):
            print(f"Uploading {file}...")
            api.upload_file(
                path_or_fileobj=file,
                path_in_repo=file,
                repo_id=REPO_ID,
                repo_type="model"
            )
            print(f"βœ“ {file} uploaded")
        else:
            print(f"⚠️ Warning: {file} not found, skipping")
            
    print("\n" + "="*50)
    print("πŸŽ‰ Upload Complete!")
    print("="*50)
    print(f"Your model is live at: https://huggingface.co/{REPO_ID}")
    print("\nDon't forget to add this link to your assignment submission!")

except Exception as e:
    print(f"\n❌ Error: {e}")