Petite-LLM-3 / deploy.py
Tonic's picture
tries to download the model at build time
19b19f0
raw
history blame
5.51 kB
#!/usr/bin/env python3
"""
Deployment script for Petite Elle L'Aime 3 Gradio Application
"""
import os
import sys
import subprocess
import argparse
import yaml
from pathlib import Path
def load_config():
"""Load configuration from config.yaml"""
config_path = Path("config.yaml")
if config_path.exists():
with open(config_path, 'r') as f:
return yaml.safe_load(f)
return {}
def check_dependencies():
"""Check if all dependencies are installed"""
print("πŸ” Checking dependencies...")
required_packages = [
'gradio',
'torch',
'transformers',
'accelerate'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
print(f"βœ… {package}")
except ImportError:
missing_packages.append(package)
print(f"❌ {package}")
if missing_packages:
print(f"\n⚠️ Missing packages: {', '.join(missing_packages)}")
print("Run: pip install -r requirements.txt")
return False
return True
def check_hardware():
"""Check hardware requirements"""
print("\nπŸ” Checking hardware...")
import psutil
# Check RAM
ram_gb = psutil.virtual_memory().total / (1024**3)
print(f"RAM: {ram_gb:.1f} GB")
if ram_gb < 8:
print("⚠️ Warning: Less than 8GB RAM detected")
print(" The application may run slowly or fail to load the model")
else:
print("βœ… RAM requirements met")
# Check GPU
try:
import torch
if torch.cuda.is_available():
gpu_name = torch.cuda.get_device_name(0)
gpu_memory = torch.cuda.get_device_properties(0).total_memory / (1024**3)
print(f"GPU: {gpu_name} ({gpu_memory:.1f} GB)")
else:
print("GPU: Not available (will use CPU)")
except:
print("GPU: Unable to detect")
return True
def install_dependencies():
"""Install dependencies from requirements.txt"""
print("\nπŸ“¦ Installing dependencies...")
if not os.path.exists("requirements.txt"):
print("❌ requirements.txt not found")
return False
try:
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
check=True, capture_output=True, text=True)
print("βœ… Dependencies installed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install dependencies: {e}")
return False
def run_tests():
"""Run the test suite"""
print("\nπŸ§ͺ Running tests...")
if not os.path.exists("test_app.py"):
print("❌ test_app.py not found")
return False
try:
result = subprocess.run([sys.executable, "test_app.py"],
capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
return result.returncode == 0
except Exception as e:
print(f"❌ Failed to run tests: {e}")
return False
def start_application(port=None, host=None):
"""Start the Gradio application"""
print("\nπŸš€ Starting application...")
config = load_config()
ui_config = config.get('ui', {})
# Use provided arguments or config defaults
port = port or ui_config.get('server_port', 7860)
host = host or ui_config.get('server_name', '0.0.0.0')
print(f"🌐 Application will be available at: http://{host}:{port}")
print("πŸ›‘ Press Ctrl+C to stop the application")
try:
subprocess.run([sys.executable, "app.py"], check=True)
except KeyboardInterrupt:
print("\nπŸ‘‹ Application stopped by user")
except subprocess.CalledProcessError as e:
print(f"❌ Failed to start application: {e}")
return False
return True
def main():
"""Main deployment function"""
parser = argparse.ArgumentParser(description="Deploy Petite Elle L'Aime 3 Gradio Application")
parser.add_argument("--install", action="store_true", help="Install dependencies")
parser.add_argument("--test", action="store_true", help="Run tests")
parser.add_argument("--check", action="store_true", help="Check system requirements")
parser.add_argument("--port", type=int, help="Port to run the application on")
parser.add_argument("--host", type=str, help="Host to bind the application to")
parser.add_argument("--start", action="store_true", help="Start the application")
args = parser.parse_args()
print("πŸ€– Petite Elle L'Aime 3 - Deployment Script\n")
# If no arguments provided, run full deployment
if not any([args.install, args.test, args.check, args.start]):
args.install = True
args.test = True
args.check = True
args.start = True
success = True
if args.install:
success &= install_dependencies()
if args.check:
success &= check_dependencies()
success &= check_hardware()
if args.test:
success &= run_tests()
if args.start and success:
start_application(args.port, args.host)
if not success:
print("\n❌ Deployment failed. Please fix the issues above.")
sys.exit(1)
else:
print("\nβœ… Deployment completed successfully!")
if __name__ == "__main__":
main()