Spaces:
Running
Running
Chaudhry Waleed commited on
Commit ·
8fbbac2
1
Parent(s): bb6c440
Deploy RICS v2 (senior baseline, CPU Spaces Dockerfile)
Browse files
backend/scripts/deploy_hf_space.ps1
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
|
| 4 |
param(
|
| 5 |
[string]$Token = $env:HF_TOKEN,
|
| 6 |
-
[string]$SpaceRepo = "Behrang987/
|
| 7 |
)
|
| 8 |
|
| 9 |
$ErrorActionPreference = "Stop"
|
|
|
|
| 3 |
|
| 4 |
param(
|
| 5 |
[string]$Token = $env:HF_TOKEN,
|
| 6 |
+
[string]$SpaceRepo = "Behrang987/myreport-space"
|
| 7 |
)
|
| 8 |
|
| 9 |
$ErrorActionPreference = "Stop"
|
backend/scripts/fetch_hf_space_logs.ps1
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Snapshot Hugging Face Space run logs (SSE endpoint).
|
| 2 |
+
# Usage (from repo root):
|
| 3 |
+
# . .\backend\scripts\load_hf_token.ps1
|
| 4 |
+
# .\backend\scripts\fetch_hf_space_logs.ps1
|
| 5 |
+
# .\backend\scripts\fetch_hf_space_logs.ps1 -SpaceRepo "Behrang987/Report-Genius"
|
| 6 |
+
# .\backend\scripts\fetch_hf_space_logs.ps1 -OutFile "docs\hf-space-logs-latest.txt"
|
| 7 |
+
#
|
| 8 |
+
# Same API as:
|
| 9 |
+
# curl -N -H "Authorization: Bearer $HF_TOKEN" \
|
| 10 |
+
# "https://huggingface.co/api/spaces/Behrang987/myreport-space/logs/run"
|
| 11 |
+
#
|
| 12 |
+
# Uses curl.exe with --max-time because the SSE stream never closes on its own.
|
| 13 |
+
|
| 14 |
+
param(
|
| 15 |
+
[string]$Token = $env:HF_TOKEN,
|
| 16 |
+
[string]$SpaceRepo = "Behrang987/myreport-space",
|
| 17 |
+
[string]$OutFile = "",
|
| 18 |
+
# Seconds to listen to the SSE stream before stopping.
|
| 19 |
+
[int]$MaxTimeSec = 25
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
$ErrorActionPreference = "Stop"
|
| 23 |
+
$RepoRoot = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
|
| 24 |
+
|
| 25 |
+
if (-not $Token) {
|
| 26 |
+
$envFile = Join-Path $RepoRoot ".env.hf"
|
| 27 |
+
if (Test-Path $envFile) {
|
| 28 |
+
Get-Content $envFile | ForEach-Object {
|
| 29 |
+
$line = $_.Trim()
|
| 30 |
+
if (-not $line -or $line.StartsWith("#")) { return }
|
| 31 |
+
if ($line -match '^HF_TOKEN=(.+)$') {
|
| 32 |
+
$Token = $Matches[1].Trim().Trim('"').Trim("'")
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (-not $Token) {
|
| 39 |
+
Write-Host "HF_TOKEN required. Set env HF_TOKEN, pass -Token, or put HF_TOKEN in .env.hf."
|
| 40 |
+
exit 1
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
$curl = Get-Command curl.exe -ErrorAction SilentlyContinue
|
| 44 |
+
if (-not $curl) {
|
| 45 |
+
Write-Host "curl.exe not found on PATH."
|
| 46 |
+
exit 1
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
$url = "https://huggingface.co/api/spaces/$SpaceRepo/logs/run"
|
| 50 |
+
Write-Host "Fetching logs (max ${MaxTimeSec}s): $url"
|
| 51 |
+
|
| 52 |
+
if (-not $OutFile) {
|
| 53 |
+
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
| 54 |
+
$safe = ($SpaceRepo -replace '[\\/]', '-')
|
| 55 |
+
$outDir = Join-Path $RepoRoot "docs\hf-space-logs"
|
| 56 |
+
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
|
| 57 |
+
$OutFile = Join-Path $outDir ($safe + "-" + $stamp + ".txt")
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
$outParent = Split-Path $OutFile -Parent
|
| 61 |
+
if ($outParent) {
|
| 62 |
+
New-Item -ItemType Directory -Force -Path $outParent | Out-Null
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
$tmpBody = Join-Path $env:TEMP ("hf-space-logs-" + [guid]::NewGuid().ToString() + ".txt")
|
| 66 |
+
$fetched = Get-Date -Format "o"
|
| 67 |
+
$header = @(
|
| 68 |
+
"# HF Space run logs",
|
| 69 |
+
"# space: $SpaceRepo",
|
| 70 |
+
"# fetched: $fetched",
|
| 71 |
+
"# url: $url",
|
| 72 |
+
"# ---",
|
| 73 |
+
""
|
| 74 |
+
) -join "`n"
|
| 75 |
+
Set-Content -Path $OutFile -Value $header -Encoding utf8
|
| 76 |
+
|
| 77 |
+
# curl exits 28 on max-time; that is expected for a live SSE stream.
|
| 78 |
+
& curl.exe -sS -N `
|
| 79 |
+
--max-time $MaxTimeSec `
|
| 80 |
+
-H "Authorization: Bearer $Token" `
|
| 81 |
+
-H "Accept: text/event-stream" `
|
| 82 |
+
$url `
|
| 83 |
+
-o $tmpBody
|
| 84 |
+
$curlExit = $LASTEXITCODE
|
| 85 |
+
if ($curlExit -ne 0 -and $curlExit -ne 28) {
|
| 86 |
+
Write-Host "curl failed with exit $curlExit"
|
| 87 |
+
if (Test-Path $tmpBody) { Remove-Item $tmpBody -Force }
|
| 88 |
+
exit $curlExit
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (Test-Path $tmpBody) {
|
| 92 |
+
$body = Get-Content -Path $tmpBody -Raw -ErrorAction SilentlyContinue
|
| 93 |
+
if ($null -eq $body) { $body = "" }
|
| 94 |
+
Add-Content -Path $OutFile -Value $body -Encoding utf8
|
| 95 |
+
Remove-Item $tmpBody -Force
|
| 96 |
+
} else {
|
| 97 |
+
$body = ""
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
Write-Host ("Wrote " + $OutFile + " (" + $body.Length + " chars, curl_exit=" + $curlExit + ")")
|
| 101 |
+
|
| 102 |
+
$lines = @()
|
| 103 |
+
if ($body) { $lines = $body -split "`r?`n" }
|
| 104 |
+
if ($lines.Count -gt 100) {
|
| 105 |
+
$tail = $lines[($lines.Count - 100)..($lines.Count - 1)]
|
| 106 |
+
} else {
|
| 107 |
+
$tail = $lines
|
| 108 |
+
}
|
| 109 |
+
Write-Host "----- log tail -----"
|
| 110 |
+
$tail | ForEach-Object { Write-Host $_ }
|