ecg-fm-api / deploy_to_hf.sh
mystic_CBK
Complete ECG-FM setup with OmegaConf 2.0.0 fix and all dependencies
eda8578
#!/bin/bash
# πŸš€ 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! πŸš€"