Spaces:
Running
Running
| # π ECG-FM Hugging Face Spaces Deployment Script (PowerShell) | |
| # This script automates the deployment process to HF Spaces on Windows | |
| param( | |
| [string]$HFUsername = "", | |
| [string]$SpaceName = "ecg-fm-api" | |
| ) | |
| # Error handling | |
| $ErrorActionPreference = "Stop" | |
| Write-Host "π Starting ECG-FM deployment to Hugging Face Spaces..." -ForegroundColor Cyan | |
| # Check if HF username is provided | |
| if ([string]::IsNullOrEmpty($HFUsername)) { | |
| Write-Host "β ERROR: Please provide your Hugging Face username" -ForegroundColor Red | |
| Write-Host "Usage: .\deploy_to_hf.ps1 -HFUsername 'your_username'" -ForegroundColor Yellow | |
| Write-Host "Or set the HFUsername parameter in the script" -ForegroundColor Yellow | |
| exit 1 | |
| } | |
| Write-Host "π Deploying to: $HFUsername/$SpaceName" -ForegroundColor Blue | |
| # Check if HF Space repository exists | |
| if (Test-Path $SpaceName) { | |
| Write-Host "β οΈ Directory $SpaceName already exists. Removing..." -ForegroundColor Yellow | |
| Remove-Item -Recurse -Force $SpaceName | |
| } | |
| # Clone the HF Space repository | |
| Write-Host "π₯ Cloning Hugging Face Space repository..." -ForegroundColor Blue | |
| git clone "https://huggingface.co/spaces/$HFUsername/$SpaceName" | |
| Set-Location $SpaceName | |
| # Copy essential files from parent directory | |
| Write-Host "π Copying migration files..." -ForegroundColor Blue | |
| Copy-Item "..\app.py" . | |
| Copy-Item "..\server.py" . | |
| Copy-Item "..\requirements.txt" . | |
| Copy-Item "..\Dockerfile" . | |
| Copy-Item "..\README.md" . | |
| Copy-Item "..\.gitattributes" . | |
| Copy-Item "..\test_imports.py" . | |
| Copy-Item "..\test_client.py" . | |
| Copy-Item "..\HF_DEPLOYMENT_GUIDE.md" . | |
| # Verify essential files are present | |
| Write-Host "β Verifying essential files..." -ForegroundColor Blue | |
| $requiredFiles = @("app.py", "server.py", "requirements.txt", "Dockerfile") | |
| foreach ($file in $requiredFiles) { | |
| if (-not (Test-Path $file)) { | |
| Write-Host "β ERROR: Required file $file is missing!" -ForegroundColor Red | |
| exit 1 | |
| } | |
| } | |
| Write-Host "β All required files copied successfully!" -ForegroundColor Green | |
| # Add all files to git | |
| Write-Host "π Adding files to git..." -ForegroundColor Blue | |
| git add . | |
| # Commit with descriptive message | |
| Write-Host "πΎ Committing changes..." -ForegroundColor Blue | |
| $commitMessage = @" | |
| Complete ECG-FM migration with robust fairseq fallback system | |
| - Migrated from fairseq-signals to main fairseq package | |
| - Implemented 4-level fallback system | |
| - Enhanced error handling and monitoring | |
| - Ready for production deployment | |
| Migration includes: | |
| β Robust import logic with multiple fallback levels | |
| β Enhanced error handling and real-time status reporting | |
| β Docker optimization for HF Spaces environment | |
| β Comprehensive testing and validation scripts | |
| "@ | |
| git commit -m $commitMessage | |
| # Push to trigger automatic build | |
| Write-Host "π Pushing to Hugging Face Spaces..." -ForegroundColor Blue | |
| git push origin main | |
| Write-Host "β Deployment initiated successfully!" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Host "π Your ECG-FM API is now being deployed to Hugging Face Spaces!" -ForegroundColor Cyan | |
| Write-Host "" | |
| Write-Host "π Next steps:" -ForegroundColor White | |
| Write-Host "1. Monitor build progress at: https://huggingface.co/spaces/$HFUsername/$SpaceName" -ForegroundColor White | |
| Write-Host "2. Wait for build completion (10-15 minutes for first build)" -ForegroundColor White | |
| Write-Host "3. Test your API endpoints once deployed" -ForegroundColor White | |
| Write-Host "4. Check the /healthz endpoint for system status" -ForegroundColor White | |
| Write-Host "" | |
| Write-Host "π Your API will be available at: https://$HFUsername-$SpaceName.hf.space" -ForegroundColor White | |
| Write-Host "" | |
| Write-Host "π For troubleshooting, see: HF_DEPLOYMENT_GUIDE.md" -ForegroundColor White | |
| Write-Host "" | |
| Write-Host "β Deployment script completed! π" -ForegroundColor Green | |
| # Return to parent directory | |
| Set-Location .. | |