File size: 6,498 Bytes
6dc8c30 |
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
#!/usr/bin/env python3
"""
Hugging Face Model Upload Script for Advanced Magnus Chess Model
"""
import os
import sys
from pathlib import Path
def upload_magnus_model():
"""Upload the Advanced Magnus Chess Model to Hugging Face"""
try:
from huggingface_hub import HfApi, upload_folder, create_repo
except ImportError:
print("β huggingface_hub not installed!")
print("Install with: pip install huggingface_hub")
return False
# Configuration
model_name = "advanced-magnus-chess-model"
print("π Authentication Setup")
print("You need a Hugging Face account and access token.")
print("Get a token at: https://huggingface.co/settings/tokens")
print()
username = input("Enter your Hugging Face username: ").strip()
if not username:
print("β Username required!")
return False
token = input(
"Enter your Hugging Face token (or press Enter to use HF_TOKEN env var): "
).strip()
if not token and "HF_TOKEN" in os.environ:
token = os.environ["HF_TOKEN"]
print("β
Using HF_TOKEN from environment")
if not token:
print("β No Hugging Face token provided!")
print("Either enter it above or set HF_TOKEN environment variable")
return False
repo_id = f"{username}/{model_name}"
print(f"\nπ Uploading model to: {repo_id}")
# Initialize API
try:
api = HfApi(token=token)
print("β
Authenticated with Hugging Face")
except Exception as e:
print(f"β Authentication failed: {e}")
return False
# Create repository
try:
create_repo(
repo_id=repo_id,
token=token,
repo_type="model",
exist_ok=True,
private=False,
)
print(f"β
Repository created/verified: {repo_id}")
except Exception as e:
print(f"β οΈ Repository creation issue: {e}")
print("This might be normal if the repository already exists.")
# Prepare README for Hugging Face
readme_content = open("README_HF.md", "r").read()
with open("README.md", "w") as f:
f.write(readme_content)
print("β
Prepared README for Hugging Face format")
# Upload the entire folder
print("\nπ€ Starting upload...")
try:
upload_folder(
folder_path=".",
repo_id=repo_id,
token=token,
repo_type="model",
commit_message="Upload Advanced Magnus Chess Model v20250626 - 2.65M parameters trained on Magnus Carlsen games",
ignore_patterns=[
".git",
"__pycache__",
"*.pyc",
".DS_Store",
"upload_instructions.py",
],
)
print(f"β
Model uploaded successfully!")
print(f"\nπ View your model at:")
print(f" https://huggingface.co/{repo_id}")
print(f"\nπ Users can now install and use your model:")
print(f" pip install huggingface_hub torch chess")
print(f" # Then download and use your model")
except Exception as e:
print(f"β Upload failed: {e}")
return False
return True
if __name__ == "__main__":
print("π― Advanced Magnus Chess Model - Hugging Face Upload")
print("π 2.65M Parameter Neural Network trained on Magnus Carlsen's games")
print("=" * 70)
# Check if we're in the right directory
if not os.path.exists("model.pth"):
print("β model.pth not found in current directory!")
print("Please run this script from the huggingface_model directory")
exit(1)
# Check model file
model_path = Path("model.pth")
model_size_mb = model_path.stat().st_size / (1024 * 1024)
print(f"π Model file: {model_path}")
print(f"π Model size: {model_size_mb:.2f} MB")
# Show model info
if os.path.exists("config.yaml"):
try:
import yaml
with open("config.yaml", "r") as f:
config = yaml.safe_load(f)
print(f"π§ Architecture: {config['model']['architecture']}")
print(f"π― Parameters: {config['training']['total_params']:,}")
print(f"π Test Accuracy: {config['metrics']['test_accuracy']:.4f}")
except ImportError:
print("π§ Architecture: AdvancedMagnusModel")
print("π― Parameters: 2,651,538")
except Exception as e:
print(f"β οΈ Could not read config: {e}")
print("\n" + "=" * 70)
proceed = input("Proceed with upload? (y/N): ").strip().lower()
if proceed == "y":
success = upload_magnus_model()
if success:
print("\nπ Upload completed successfully!")
print("Your Advanced Magnus Chess Model is now available on Hugging Face!")
print("The chess community can now benefit from your Magnus AI! π")
else:
print("\nβ Upload failed. Please check your credentials and try again.")
else:
print("Upload cancelled.")
if __name__ == "__main__":
print("π― Advanced Magnus Chess Model - Hugging Face Upload")
print("=" * 60)
# Check if we're in the right directory
if not os.path.exists("model.pth"):
print("β model.pth not found in current directory!")
print("Please run this script from the huggingface_model directory")
exit(1)
# Check model file
model_path = Path("model.pth")
model_size_mb = model_path.stat().st_size / (1024 * 1024)
print(f"π Model file: {model_path}")
print(f"π Model size: {model_size_mb:.2f} MB")
# Show model info
if os.path.exists("config.yaml"):
with open("config.yaml", "r") as f:
config = yaml.safe_load(f)
print(f"π§ Architecture: {config['model']['architecture']}")
print(f"π― Parameters: {config['training']['total_params']:,}")
print(f"π Test Accuracy: {config['metrics']['test_accuracy']:.4f}")
print("\n" + "=" * 60)
proceed = input("Proceed with upload? (y/N): ").strip().lower()
if proceed == "y":
success = upload_magnus_model()
if success:
print("\nπ Upload completed successfully!")
print("Your model is now available on Hugging Face!")
else:
print("\nβ Upload failed. Please check your credentials and try again.")
else:
print("Upload cancelled.")
|