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"