Download scripts/PublishToHuggingFace.ps1 from Ian26/MarsLM: direct link, hf CLI and curl.
- Browser
- Download file 4.19 kB
-
https://huggingface.co/Ian26/MarsLM/resolve/main/scripts/PublishToHuggingFace.ps1
- Command line
-
hf download hf://Ian26/MarsLM/scripts/PublishToHuggingFace.ps1
-
curl -L -o PublishToHuggingFace.ps1 https://huggingface.co/Ian26/MarsLM/resolve/main/scripts/PublishToHuggingFace.ps1
4.19 kB
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$RepoId, | |
| [string]$Token, | |
| [switch]$Private, | |
| [switch]$DryRun | |
| ) | |
| $ErrorActionPreference = "Stop" | |
| $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path | |
| $repoRoot = Resolve-Path (Join-Path $scriptPath "..") | |
| Set-Location $repoRoot | |
| $checkpointPath = Join-Path $repoRoot "artifacts/checkpoints/marslm-final.pt" | |
| $configPath = Join-Path $repoRoot "artifacts/checkpoints/config.json" | |
| $tokenizerPath = Join-Path $repoRoot "artifacts/tokenizer/marslm.json" | |
| $requiredFiles = @( | |
| $checkpointPath, | |
| $configPath, | |
| $tokenizerPath | |
| ) | |
| foreach ($file in $requiredFiles) { | |
| if (-not (Test-Path $file)) { | |
| throw "No se encontr贸 el archivo requerido: $file" | |
| } | |
| } | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "Publicando MarsLM en Hugging Face Hub" -ForegroundColor Cyan | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "Repo: $RepoId" -ForegroundColor Green | |
| Write-Host "" | |
| if ($DryRun) { | |
| Write-Host "Modo de prueba: no se subir谩 nada." -ForegroundColor Yellow | |
| Write-Host "Archivos que se publicar铆an:" -ForegroundColor Yellow | |
| foreach ($file in $requiredFiles) { | |
| Write-Host " - $file" -ForegroundColor Yellow | |
| } | |
| return | |
| } | |
| # Buscar token | |
| $token = $Token | |
| if (-not $token) { | |
| $token = $env:HF_TOKEN | |
| } | |
| # Token antiguo | |
| if (-not $token) { | |
| $tokenFile = Join-Path $HOME ".huggingface\token" | |
| if (Test-Path $tokenFile) { | |
| $token = (Get-Content $tokenFile -Raw).Trim() | |
| } | |
| } | |
| # Token moderno hf auth login | |
| if (-not $token) { | |
| $hfTokenPath = Join-Path $HOME ".cache\huggingface\token" | |
| if (Test-Path $hfTokenPath) { | |
| $token = (Get-Content $hfTokenPath -Raw).Trim() | |
| } | |
| } | |
| # Pedir token manualmente | |
| if (-not $token) { | |
| Write-Host "" | |
| Write-Host "No se encontr贸 un token guardado." -ForegroundColor Yellow | |
| Write-Host "Ejecuta: hf auth login" -ForegroundColor Yellow | |
| Write-Host "" | |
| $token = Read-Host "Introduce tu token de Hugging Face" | |
| } | |
| if (-not $token) { | |
| throw "No se proporcion贸 ning煤n token." | |
| } | |
| $pythonCode = @" | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| from huggingface_hub.errors import HfHubHTTPError | |
| repo_id = os.environ['REPO_ID'] | |
| private = os.environ.get('PRIVATE', '0') == '1' | |
| files = [ | |
| Path('artifacts/checkpoints/marslm-final.pt'), | |
| Path('artifacts/checkpoints/config.json'), | |
| Path('artifacts/tokenizer/marslm.json'), | |
| ] | |
| token = os.environ.get('HF_TOKEN') | |
| if not token: | |
| raise RuntimeError('No hay token HF disponible') | |
| api = HfApi(token=token) | |
| try: | |
| print("Creando repositorio...") | |
| api.create_repo( | |
| repo_id=repo_id, | |
| exist_ok=True, | |
| private=private, | |
| repo_type="model" | |
| ) | |
| for path in files: | |
| print(f"Subiendo {path}") | |
| api.upload_file( | |
| path_or_fileobj=str(path), | |
| path_in_repo=path.as_posix().split('artifacts/',1)[1], | |
| repo_id=repo_id, | |
| repo_type="model", | |
| ) | |
| except HfHubHTTPError as exc: | |
| print( | |
| f"UPLOAD_FAILED: {exc}", | |
| file=sys.stderr | |
| ) | |
| raise | |
| print("Upload completed") | |
| "@ | |
| $tempScript = Join-Path $env:TEMP "publish_marslm.py" | |
| Set-Content ` | |
| -Path $tempScript ` | |
| -Value $pythonCode ` | |
| -Encoding UTF8 | |
| $env:REPO_ID = $RepoId | |
| $env:PRIVATE = if ($Private) { "1" } else { "0" } | |
| $env:HF_TOKEN = $token | |
| python $tempScript | |
| $exitCode = $LASTEXITCODE | |
| Remove-Item $tempScript -Force -ErrorAction SilentlyContinue | |
| if ($exitCode -ne 0) { | |
| throw "La publicaci贸n fall贸 en Hugging Face Hub." | |
| } | |
| Write-Host "" | |
| Write-Host "========================================" -ForegroundColor Green | |
| Write-Host "Modelo publicado correctamente." -ForegroundColor Green | |
| Write-Host "========================================" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Host "Repositorio:" | |
| Write-Host "https://huggingface.co/$RepoId" |