param( [string]$Space = "nenae18/leechard" # "/" ) # Deploy the (flat) backend app folder straight to the Hugging Face Space. # Uses the locally CACHED HF write token (the user's fine-grained token lacks Space # write -> 403). FAL_KEY / ACCESS_CODE / ANDROID_ASSETLINKS_JSON stay as Space secrets. $ErrorActionPreference = "Stop" $Backend = Split-Path -Parent $PSScriptRoot # scripts/ lives inside backend/, parent = backend $env:HF_TOKEN = (python -c "from huggingface_hub import get_token; print(get_token() or '')").Trim() if (-not $env:HF_TOKEN -or $env:HF_TOKEN.Length -lt 10) { Write-Host "FAIL: no cached HF token. Run: python -c `"from huggingface_hub import login; login()`"" exit 1 } $bf = $Backend.Replace('\', '/') $py = @" import os from huggingface_hub import HfApi api = HfApi(token=os.environ['HF_TOKEN']) me = api.whoami() role = ((me.get('auth') or {}).get('accessToken') or {}).get('role') print('TOKEN_OK user=' + str(me.get('name')) + ' role=' + str(role)) # The Space already exists; skip create_repo (free Docker Spaces now 402 on create). # Only create as a best-effort fallback when the repo is genuinely missing. if not api.repo_exists('$Space', repo_type='space'): api.create_repo(repo_id='$Space', repo_type='space', space_sdk='docker', exist_ok=True) api.upload_folder( folder_path=r'$bf', repo_id='$Space', repo_type='space', commit_message='Deploy SalonView AI (brand single-source)', # upload_folder 는 .gitignore 를 보지 않는다 — 여기 없는 파일은 전부 Space 로 올라간다. # docs/ = 영업자료(가격표·신청서), CLAUDE.md/.claude = 내부 메모·개발설정. # Space 는 공개라 절대 올리면 안 된다. ignore_patterns=['tests/*', '.git/*', '**/__pycache__/*', '*.pyc', '.pytest_cache/*', '*.db', '*.db-wal', '*.db-shm', 'preview_ui*', 'dev_local*', '.env', 'docs/*', 'CLAUDE.md', '.claude/*', 'static/_shots/*', 'static/_brand_preview.html'], ) print('UPLOAD_OK') "@ $py | python - $env:HF_TOKEN = "" if ($LASTEXITCODE -ne 0) { Write-Host "FAIL: upload failed."; exit 1 } $liveHost = $Space.Replace("/", "-") Write-Host "Uploaded. Live URL after build: https://$liveHost.hf.space"