File size: 3,389 Bytes
7b97436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
"""
Загрузка модели в Model репозиторий через HF CLI (без git)
⚡ Намного надежнее для больших файлов чем git push!
"""

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

HF_TOKEN = os.environ.get("HF_TOKEN", "hf_YOUR_TOKEN_HERE")  # Замените на ваш токен
MODEL_REPO = "Gerchegg/Qwen-Soloband-Diffusers"
LOCAL_MODEL_DIR = "Qwen-ImageForFlo_2/model"  # Упакованная модель

print(f"""
============================================================
  UPLOAD MODEL VIA HF API
============================================================

Advantages:
   - Auto retry on errors
   - Resumable upload
   - Progress bars
   - Optimized for large files
   
Plan:
   1. Create Model repo: {MODEL_REPO}
   2. Upload model/ folder (58GB) via HF API
   
No limits for Model repositories!
Time: 30-60 minutes
""")

# Проверка наличия модели
if not Path(LOCAL_MODEL_DIR).exists():
    print(f"ERROR: Model not found in {LOCAL_MODEL_DIR}")
    print(f"   Run first: python download_and_pack_model.py")
    exit(1)

# Проверка размера
total_size = sum(f.stat().st_size for f in Path(LOCAL_MODEL_DIR).rglob('*') if f.is_file())
print(f"Model size: {total_size / 1024**3:.1f} GB")

print("\nStarting upload...")

# Инициализация API
api = HfApi(token=HF_TOKEN)

print("\n" + "="*60)
print("STEP 1: Creating Model Repository")
print("="*60)

try:
    print(f"\nCreating {MODEL_REPO}...")
    create_repo(
        repo_id=MODEL_REPO,
        repo_type="model",
        exist_ok=True,
        token=HF_TOKEN
    )
    print(f"OK Repository created/exists")
    print(f"  URL: https://huggingface.co/{MODEL_REPO}")
except Exception as e:
    print(f"ERROR creating repository: {e}")
    exit(1)

print("\n" + "="*60)
print("STEP 2: Uploading Model via HF API")
print("="*60)

print(f"\nUploading folder {LOCAL_MODEL_DIR}/ -> {MODEL_REPO}")
print("   Using upload_folder API")
print("   Supports resumable uploads")
print("   Progress will be shown automatically\n")

try:
    # Загружаем всю папку
    api.upload_folder(
        folder_path=LOCAL_MODEL_DIR,
        repo_id=MODEL_REPO,
        repo_type="model",
        token=HF_TOKEN,
        commit_message="Add Qwen-Soloband model in diffusers format (58GB with custom transformer)",
        ignore_patterns=["*.pyc", "__pycache__", ".git*"]
    )
    
    print("\n" + "="*60)
    print("SUCCESS! MODEL UPLOADED!")
    print("="*60)
    
    print(f"\nModel repository ready!")
    print(f"   URL: https://huggingface.co/{MODEL_REPO}")
    print(f"   Size: ~58GB")
    
    print(f"\nView contents:")
    print(f"   https://huggingface.co/{MODEL_REPO}/tree/main")
    
    print(f"\nNext step:")
    print(f"   Run: python create_space_v2_simple.py")
    print(f"   This creates Space that loads from this Model repo")
    
except Exception as e:
    print(f"\nERROR uploading: {e}")
    import traceback
    print(traceback.format_exc())
    
    print("\nWhat you can do:")
    print("   1. Try again - upload_folder supports resuming")
    print("   2. Check internet connection")
    print("   3. Check HF storage space (PRO gives enough)")
    
    print("\nTo retry, just run again:")
    print("   python upload_model_hf_cli.py")

print("\nDone!")