memo / deploy_memo.py
likhonsheikh's picture
Add deployment script for multiple platforms
fa6a36b verified
#!/usr/bin/env python3
"""
Memo Model Deployment Script
Deploy Memo to various platforms and environments
"""
import os
import sys
import subprocess
import json
from pathlib import Path
def check_requirements():
"""Check if all requirements are met for deployment"""
print("πŸ” Checking deployment requirements...")
# Check if we're in the right directory
required_files = [
'api/main.py',
'requirements.txt',
'README.md',
'config/model_tiers.py'
]
missing_files = []
for file in required_files:
if not os.path.exists(file):
missing_files.append(file)
if missing_files:
print(f"❌ Missing required files: {missing_files}")
return False
print("βœ… All required files present")
return True
def deploy_local():
"""Deploy Memo locally for testing"""
print("πŸš€ Deploying Memo locally...")
try:
# Install dependencies
print("πŸ“¦ Installing dependencies...")
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
# Start the API server
print("🌐 Starting API server on http://localhost:8000")
subprocess.run([sys.executable, "api/main.py"])
except subprocess.CalledProcessError as e:
print(f"❌ Local deployment failed: {e}")
return False
return True
def create_dockerfile():
"""Create a Dockerfile for containerized deployment"""
print("πŸ“¦ Creating Dockerfile...")
dockerfile_content = '''FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \\
build-essential \\
curl \\
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Expose the API port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \\
CMD curl -f http://localhost:8000/health || exit 1
# Start the API server
CMD ["python", "api/main.py"]
'''
with open('Dockerfile', 'w') as f:
f.write(dockerfile_content)
print("βœ… Dockerfile created successfully")
return True
def create_docker_compose():
"""Create docker-compose.yml for multi-service deployment"""
print("πŸ”§ Creating docker-compose.yml...")
compose_content = '''version: '3.8'
services:
memo-api:
build: .
ports:
- "8000:8000"
environment:
- ENVIRONMENT=production
- LOG_LEVEL=INFO
volumes:
- ./logs:/app/logs
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
redis:
image: redis:alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
restart: unless-stopped
volumes:
redis_data:
'''
with open('docker-compose.yml', 'w') as f:
f.write(compose_content)
print("βœ… docker-compose.yml created successfully")
return True
def deploy_huggingface_inference():
"""Instructions for Hugging Face Inference API deployment"""
print("🌐 Hugging Face Inference API Deployment")
print("=" * 50)
instructions = """
To deploy your Memo model on Hugging Face Inference API:
1. Go to: https://huggingface.co/likhonsheikh/memo
2. Click "Ask for provider support" (as shown in your screenshot)
3. Fill out the deployment request form with:
- Model description: "Production-grade text-to-video generation with Transformers + Safetensors"
- Use case: "Bangla text to video content generation"
- Expected usage: "API endpoints for video generation"
- Performance requirements: "4-16GB memory, GPU preferred"
4. Hugging Face will review and deploy your model if approved
Benefits:
βœ… Automatic scaling
βœ… Global CDN
βœ… Pay-per-use pricing
βœ… No infrastructure management
βœ… Professional SLA
"""
print(instructions)
return True
def create_cloud_deployment_scripts():
"""Create deployment scripts for various cloud platforms"""
print("☁️ Creating cloud deployment scripts...")
# AWS deployment script
aws_script = '''#!/bin/bash
# AWS Deployment Script for Memo
echo "πŸš€ Deploying Memo to AWS..."
# Build and push Docker image
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
docker build -t memo-api .
docker tag memo-api:latest $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/memo-api:latest
docker push $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/memo-api:latest
# Deploy to ECS
aws ecs create-service \\
--cluster memo-cluster \\
--service-name memo-api \\
--task-definition memo-task \\
--desired-count 1 \\
--launch-type FARGATE \\
--network-configuration "awsvpcConfiguration={subnets=[subnet-12345],securityGroups=[sg-12345],assignPublicIp=ENABLED}"
'''
with open('deploy-aws.sh', 'w') as f:
f.write(aws_script)
os.chmod('deploy-aws.sh', 0o755)
# Google Cloud deployment script
gcp_script = '''#!/bin/bash
# Google Cloud Deployment Script for Memo
echo "πŸš€ Deploying Memo to Google Cloud..."
# Build and push Docker image
gcloud builds submit --tag gcr.io/$PROJECT_ID/memo-api
# Deploy to Cloud Run
gcloud run deploy memo-api \\
--image gcr.io/$PROJECT_ID/memo-api \\
--platform managed \\
--region us-central1 \\
--allow-unauthenticated \\
--memory 8Gi \\
--cpu 2 \\
--max-instances 10 \\
--min-instances 0
'''
with open('deploy-gcp.sh', 'w') as f:
f.write(gcp_script)
os.chmod('deploy-gcp.sh', 0o755)
print("βœ… Cloud deployment scripts created")
return True
def main():
"""Main deployment function"""
print("πŸš€ Memo Model Deployment Script")
print("=" * 50)
if not check_requirements():
print("❌ Requirements check failed. Please ensure you're in the Memo directory.")
sys.exit(1)
print("\nChoose deployment option:")
print("1. Local deployment (for testing)")
print("2. Create Dockerfile")
print("3. Create docker-compose.yml")
print("4. Hugging Face Inference API instructions")
print("5. Create cloud deployment scripts")
print("6. All of the above")
choice = input("\nEnter your choice (1-6): ").strip()
if choice == "1":
deploy_local()
elif choice == "2":
create_dockerfile()
elif choice == "3":
create_docker_compose()
elif choice == "4":
deploy_huggingface_inference()
elif choice == "5":
create_cloud_deployment_scripts()
elif choice == "6":
create_dockerfile()
create_docker_compose()
deploy_huggingface_inference()
create_cloud_deployment_scripts()
print("\nβœ… All deployment options prepared!")
print("\nNext steps:")
print("1. For local testing: python api/main.py")
print("2. For Docker: docker-compose up")
print("3. For cloud deployment: Use the created scripts")
print("4. For Hugging Face: Follow the instructions above")
else:
print("❌ Invalid choice")
sys.exit(1)
if __name__ == "__main__":
main()