# 🚀 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 ..