ecg-fm-api / deploy_to_hf.ps1
mystic_CBK
Complete ECG-FM setup with OmegaConf 2.0.0 fix and all dependencies
eda8578
raw
history blame
3.89 kB
# πŸš€ 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 ..