# Deploy RGB Metrics to Hugging Face Spaces # Windows PowerShell Script # Usage: .\deploy_to_hf.ps1 Write-Host "`nRGB Metrics - HF Spaces Deployment Script" -ForegroundColor Green Write-Host "=============================================`n" -ForegroundColor Green # Check if git is installed try { git --version | Out-Null } catch { Write-Host "Git not found. Please install git first." -ForegroundColor Red exit 1 } # Get user inputs $HF_USERNAME = Read-Host "Enter your HF username (e.g., gopikrishnait)" $SPACE_NAME = Read-Host "Enter your space name (e.g., RGBMetrics)" $HF_TOKEN = Read-Host "Enter your HF token (get from https://huggingface.co/settings/tokens)" -AsSecureString # Convert secure string to plain text for git $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($HF_TOKEN) $HF_TOKEN_PLAIN = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) $SPACE_URL = "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" $GIT_URL = "https://$($HF_USERNAME):$($HF_TOKEN_PLAIN)@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" Write-Host "Deployment Configuration:" -ForegroundColor Cyan Write-Host " HF Username: $HF_USERNAME" Write-Host " Space Name: $SPACE_NAME" Write-Host " Space URL: $SPACE_URL`n" # Check if space directory exists if (!(Test-Path $SPACE_NAME)) { Write-Host "Cloning space repository..." -ForegroundColor Blue git clone $GIT_URL $SPACE_NAME Set-Location $SPACE_NAME } else { Write-Host "Using existing space directory..." -ForegroundColor Blue Set-Location $SPACE_NAME git pull } Write-Host "`nCopying application files..." -ForegroundColor Blue # Copy main files if (Test-Path "..\app.py") { Copy-Item "..\app.py" . -Force Write-Host " Copied app.py" } else { Write-Host " app.py not found in parent directory" -ForegroundColor Yellow } if (Test-Path "..\requirements.txt") { Copy-Item "..\requirements.txt" . -Force Write-Host " Copied requirements.txt" } else { Write-Host " requirements.txt not found" -ForegroundColor Yellow } # Copy source code if (Test-Path "..\src") { if (Test-Path "src") { Remove-Item "src" -Recurse -Force } Copy-Item "..\src" . -Recurse -Force Write-Host " Copied src/" } # Copy README if (Test-Path "..\HF_SPACE_README.md") { Copy-Item "..\HF_SPACE_README.md" "README.md" -Force Write-Host " Copied README.md" } Write-Host "`nChecking files..." -ForegroundColor Blue Get-Item "app.py", "requirements.txt", "README.md" -ErrorAction SilentlyContinue | ForEach-Object { Write-Host " $_" } Write-Host "`nGit operations..." -ForegroundColor Blue # Configure git for HF git config --local user.name "RGB Deployment Bot" git config --local user.email "deploy@rgb.local" # Add all files git add . # Check if there are changes git diff --cached --quiet $hasChanges = $LASTEXITCODE if ($hasChanges -ne 0) { Write-Host " Committing changes..." $timestamp = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") git commit -m "Deploy RGB Metrics dashboard - $timestamp" Write-Host " Pushing to HF Spaces..." -ForegroundColor Yellow git push -u origin main if ($LASTEXITCODE -eq 0) { Write-Host " Push successful!" -ForegroundColor Green } else { Write-Host " Push failed. Check your token and permissions." -ForegroundColor Red } } else { Write-Host " No changes to commit" } Write-Host "`nDeployment completed!" -ForegroundColor Green Write-Host "`nIMPORTANT: Set your GROQ_API_KEY secret:" -ForegroundColor Cyan Write-Host " 1. Go to: $SPACE_URL" Write-Host " 2. Click Settings in top right" Write-Host " 3. Scroll to 'Repository secrets'" Write-Host " 4. Click 'Add a secret'" Write-Host " 5. Key: GROQ_API_KEY" Write-Host " 6. Value: [Your Groq API key from https://console.groq.com/]" Write-Host " 7. Click 'Add secret'" Write-Host "`nYour space will be live in 2-3 minutes!" Write-Host " View it at: $SPACE_URL`n" # Cleanup [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)