Spaces:
Paused
Paused
| param( | |
| [string]$BaseUrl = "https://seungminkwak-puppeteer-api.hf.space", | |
| [string]$Token = "", | |
| [string]$MeshUrl = "https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Sample-Models@master/2.0/CesiumMan/glTF-Binary/CesiumMan.glb", | |
| [string]$Workdir = "job-cesium", | |
| [int]$MaxTries = 12, | |
| [int]$DelaySec = 10 | |
| ) | |
| $ErrorActionPreference = "Stop" | |
| Write-Host "=== Puppeteer API quick test ===" | |
| Write-Host "[1] /health" | |
| $health = Invoke-RestMethod -Uri "$BaseUrl/health" -Headers @{ Authorization = "Bearer $Token" } | |
| $health | ConvertTo-Json -Depth 6 | Write-Host | |
| Write-Host "[2] /rig" | |
| $body = @{ mesh_url = $MeshUrl; workdir = $Workdir } | ConvertTo-Json -Depth 6 | |
| $resp = Invoke-RestMethod -Uri "$BaseUrl/rig" -Headers @{ Authorization = "Bearer $Token"; "Content-Type"="application/json" } -Method POST -Body $body | |
| $resp | ConvertTo-Json -Depth 6 | Write-Host | |
| Write-Host "[3] Poll /list" | |
| $files = @() | |
| for ($i=1; $i -le $MaxTries; $i++) { | |
| try { | |
| $list = Invoke-RestMethod -Uri "$BaseUrl/list" -Headers @{ Authorization = "Bearer $Token" } | |
| if ($list.files_preview) { | |
| $files = $list.files_preview | |
| Write-Host (" -> Found: {0}" -f ($files -join ", ")) | |
| break | |
| } else { | |
| Write-Host (" -> Try {0}/{1}: no files yet" -f $i, $MaxTries) | |
| } | |
| } catch { | |
| Write-Host (" -> Try {0}/{1}: error {2}" -f $i, $MaxTries, $_.Exception.Message) | |
| } | |
| Start-Sleep -Seconds $DelaySec | |
| } | |
| if (-not $files -or $files.Count -eq 0) { | |
| Write-Host "No result files found." -ForegroundColor Red | |
| exit 2 | |
| } | |
| # choose a file | |
| $preferred = "/data/results/rigged.glb" | |
| $target = if ($files -contains $preferred) { $preferred } else { $files[0] } | |
| Write-Host ("[4] Download {0}" -f $target) | |
| $enc = [uri]::EscapeDataString($target) | |
| $newDir = Join-Path $PWD "results" | |
| New-Item -ItemType Directory -Path $newDir -Force | Out-Null | |
| $out = Join-Path $newDir (Split-Path -Leaf $target) | |
| Invoke-WebRequest -Uri "$BaseUrl/download?path=$enc" -Headers @{ Authorization = "Bearer $Token" } -OutFile $out | |
| Write-Host ("Saved to {0}" -f $out) | |
| try { ii $out | Out-Null } catch {} | |
| Write-Host "=== Done ===" | |