File size: 7,450 Bytes
fa6a36b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
#!/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() |