| param( |
| [string]$RepoId = "build-small-hackathon/ai-time-machine", |
| [string]$CommitMessage = "Prepare AI Time Machine hackathon Space", |
| [switch]$ConfigureRuntime |
| ) |
|
|
| $ErrorActionPreference = "Stop" |
|
|
| $root = Split-Path -Parent $PSScriptRoot |
| $includePatterns = @( |
| ".env.example", |
| ".gitattributes", |
| ".hfignore", |
| "README.md", |
| "app.py", |
| "pyproject.toml", |
| "requirements.txt", |
| "config/**", |
| "fixtures/**", |
| "src/**", |
| "static/**", |
| "docs/*.md", |
| "scripts/*.py", |
| "scripts/*.ps1" |
| ) |
| $excludePatterns = @( |
| ".git/**", |
| ".agent/**", |
| ".idea/**", |
| ".gradio/**", |
| ".playwright-mcp/**", |
| ".pytest_cache/**", |
| "pytest_temp/**", |
| ".runtime-venv/**", |
| ".venv/**", |
| "__pycache__/**", |
| "**/__pycache__/**", |
| "*.pyc", |
| ".DS_Store", |
| ".env", |
| "data/**", |
| "logs/**", |
| "docs/images/**", |
| "docs/diagrams/**", |
| "tests/**", |
| "evals/**", |
| "src/ai_time_machine.egg-info/**" |
| ) |
| $hf = Join-Path $root ".runtime-venv\Scripts\hf.exe" |
| if (-not (Test-Path $hf)) { |
| $hf = Join-Path $root ".venv\Scripts\hf.exe" |
| } |
| if (-not (Test-Path $hf)) { |
| throw "Hugging Face CLI was not found. Install huggingface_hub into .runtime-venv or .venv." |
| } |
| $python = Join-Path $root ".runtime-venv\Scripts\python.exe" |
| if (-not (Test-Path $python)) { |
| $python = Join-Path $root ".venv\Scripts\python.exe" |
| } |
| if ($ConfigureRuntime -and -not (Test-Path $python)) { |
| throw "Python was not found in .runtime-venv or .venv; cannot configure runtime variables." |
| } |
|
|
| Push-Location $root |
| try { |
| $whoami = & $hf auth whoami 2>&1 |
| $whoamiText = ($whoami | Out-String).Trim() |
| if ($LASTEXITCODE -ne 0 -or $whoamiText -match "Not logged in") { |
| throw "Hugging Face CLI is not logged in. Run: $hf auth login" |
| } |
| Write-Host $whoamiText |
|
|
| & $hf repo create $RepoId --repo-type space --space_sdk gradio --exist-ok |
| if ($LASTEXITCODE -ne 0) { |
| throw "Failed to create or verify Space repo $RepoId." |
| } |
|
|
| & $hf upload $RepoId . . --repo-type space --commit-message $CommitMessage --include $includePatterns --exclude $excludePatterns --delete $excludePatterns |
| if ($LASTEXITCODE -ne 0) { |
| throw "Failed to upload Space repo $RepoId." |
| } |
|
|
| Write-Host "Uploaded Space: https://huggingface.co/spaces/$RepoId" |
|
|
| if ($ConfigureRuntime) { |
| & $python scripts\configure_hf_space.py --repo-id $RepoId |
| if ($LASTEXITCODE -ne 0) { |
| throw "Failed to configure Space runtime for $RepoId." |
| } |
| } |
| } |
| finally { |
| Pop-Location |
| } |
|
|