Spaces:
Sleeping
Sleeping
| # π ECG-FM Hugging Face Spaces Deployment Script | |
| # This script automates the deployment process to HF Spaces | |
| set -e # Exit on any error | |
| echo "π Starting ECG-FM deployment to Hugging Face Spaces..." | |
| # Configuration | |
| SPACE_NAME="ecg-fm-api" | |
| HF_USERNAME="" # Set this to your HF username | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| # Function to print colored output | |
| print_status() { | |
| echo -e "${BLUE}[INFO]${NC} $1" | |
| } | |
| print_success() { | |
| echo -e "${GREEN}[SUCCESS]${NC} $1" | |
| } | |
| print_warning() { | |
| echo -e "${YELLOW}[WARNING]${NC} $1" | |
| } | |
| print_error() { | |
| echo -e "${RED}[ERROR]${NC} $1" | |
| } | |
| # Check if HF username is set | |
| if [ -z "$HF_USERNAME" ]; then | |
| print_error "Please set HF_USERNAME in the script or export it as environment variable" | |
| print_status "Example: export HF_USERNAME=your_username" | |
| exit 1 | |
| fi | |
| print_status "Deploying to: $HF_USERNAME/$SPACE_NAME" | |
| # Check if HF Space repository exists | |
| if [ -d "$SPACE_NAME" ]; then | |
| print_warning "Directory $SPACE_NAME already exists. Removing..." | |
| rm -rf "$SPACE_NAME" | |
| fi | |
| # Clone the HF Space repository | |
| print_status "Cloning Hugging Face Space repository..." | |
| git clone "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| cd "$SPACE_NAME" | |
| # Copy essential files from parent directory | |
| print_status "Copying migration files..." | |
| cp ../app.py . | |
| cp ../server.py . | |
| cp ../requirements.txt . | |
| cp ../Dockerfile . | |
| cp ../README.md . | |
| cp ../.gitattributes . | |
| cp ../test_imports.py . | |
| cp ../test_client.py . | |
| cp ../HF_DEPLOYMENT_GUIDE.md . | |
| # Verify essential files are present | |
| print_status "Verifying essential files..." | |
| required_files=("app.py" "server.py" "requirements.txt" "Dockerfile") | |
| for file in "${required_files[@]}"; do | |
| if [ ! -f "$file" ]; then | |
| print_error "Required file $file is missing!" | |
| exit 1 | |
| fi | |
| done | |
| print_success "All required files copied successfully!" | |
| # Add all files to git | |
| print_status "Adding files to git..." | |
| git add . | |
| # Commit with descriptive message | |
| print_status "Committing changes..." | |
| git commit -m "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" | |
| # Push to trigger automatic build | |
| print_status "Pushing to Hugging Face Spaces..." | |
| git push origin main | |
| print_success "Deployment initiated successfully!" | |
| echo "" | |
| echo "π Your ECG-FM API is now being deployed to Hugging Face Spaces!" | |
| echo "" | |
| echo "π Next steps:" | |
| echo "1. Monitor build progress at: https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| echo "2. Wait for build completion (10-15 minutes for first build)" | |
| echo "3. Test your API endpoints once deployed" | |
| echo "4. Check the /healthz endpoint for system status" | |
| echo "" | |
| echo "π Your API will be available at: https://$HF_USERNAME-$SPACE_NAME.hf.space" | |
| echo "" | |
| echo "π For troubleshooting, see: HF_DEPLOYMENT_GUIDE.md" | |
| echo "" | |
| print_success "Deployment script completed! π" | |