#!/usr/bin/env python3 """ Utility script to initialize the SDXL model cache for faster thumbnail generation. Run this script once to download and cache the base SDXL model to Modal storage. After running this, all future thumbnail generations will be much faster since the model won't need to be downloaded from HuggingFace each time. Usage: python modal_deployments/cache_model.py """ import modal import sys def main(): """Initialize the SDXL model cache""" print("šŸš€ Starting SDXL model cache initialization...") print("ā° This will take about 5-10 minutes but only needs to be done once.") print("šŸ’” After this completes, all future thumbnail generations will be much faster!\n") try: # Use Modal CLI to call the function directly import subprocess print("šŸ”§ Calling Modal function via CLI...") result = subprocess.run([ "modal", "run", "modal_deployments.modal_functions::initialize_model_cache" ], capture_output=True, text=True, timeout=1800) if result.returncode == 0: print("āœ… SUCCESS!") print("SDXL model cached successfully! Future generations will be much faster.") print("\nšŸŽ‰ Your SDXL model is now cached! Future thumbnail generations will be much faster.") print("šŸ“ˆ Expected speedup: ~30-40 seconds saved per generation") else: print("āŒ ERROR!") print("Failed to cache SDXL model.") print(f"Error output: {result.stderr}") return 1 except subprocess.TimeoutExpired: print("ā° Cache initialization is taking longer than expected (30 minutes).") print("This is normal for the first download. Please check Modal dashboard for progress.") return 1 except Exception as e: print(f"āŒ Failed to initialize model cache: {e}") print("\nšŸ”§ Troubleshooting:") print("1. Make sure you have Modal CLI installed and configured") print("2. Ensure your Modal app is deployed: modal deploy modal_deployments/modal_functions.py") print("3. Check your internet connection") return 1 return 0 if __name__ == "__main__": sys.exit(main())