File size: 4,191 Bytes
7afadff | 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 | 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" |