Download scripts_reference/upload_model_hf_cli.py from Gerchegg/Qwen-Model-Converter: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/spaces/Gerchegg/Qwen-Model-Converter/resolve/main/scripts_reference/upload_model_hf_cli.py
- Command line
-
hf download hf://spaces/Gerchegg/Qwen-Model-Converter/scripts_reference/upload_model_hf_cli.py
-
curl -L -o upload_model_hf_cli.py https://huggingface.co/spaces/Gerchegg/Qwen-Model-Converter/resolve/main/scripts_reference/upload_model_hf_cli.py
3.39 kB
| """ | |
| Загрузка модели в 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!") | |