|
|
|
""" |
|
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 |
|
|
|
|
|
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}") |
|
|
|
|
|
try: |
|
api = HfApi(token=token) |
|
print("β
Authenticated with Hugging Face") |
|
except Exception as e: |
|
print(f"β Authentication failed: {e}") |
|
return False |
|
|
|
|
|
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.") |
|
|
|
|
|
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") |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
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") |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
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") |
|
|
|
|
|
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.") |
|
|