#!/usr/bin/env python3 """ HuggingFace Spaces startup script This ensures all necessary directories exist when deployed to HF Spaces """ import os import sys from pathlib import Path def ensure_hf_directories(): """Ensure all necessary directories exist for HuggingFace Spaces""" print("🌐 HuggingFace Spaces - Setting up directories...") # Essential directories that must exist essential_dirs = [ "Generated", "static", "view_session" ] for dir_name in essential_dirs: dir_path = Path(dir_name) if not dir_path.exists(): dir_path.mkdir(exist_ok=True, mode=0o755) print(f"✅ Created: {dir_name}/") else: # Ensure correct permissions try: dir_path.chmod(0o755) print(f"✅ Verified: {dir_name}/") except Exception: pass print("✅ All essential directories ready for HuggingFace Spaces") # Run directory setup immediately when this module is imported ensure_hf_directories() # Import the main app if __name__ == "__main__": # This will be the main entry point for HuggingFace Spaces print("🚀 Starting BytePlus Image Generation Studio on HuggingFace Spaces") # Import and run the main app try: # The main app code should be in app.py in the HF Space import app as main_app # The app should have a demo object that can be launched if hasattr(main_app, "demo"): print("✅ Found demo object, launching...") main_app.demo.launch() elif hasattr(main_app, "create_interface"): print("✅ Found create_interface function, launching...") demo = main_app.create_interface() demo.launch() else: print("❌ Could not find demo or create_interface in app.py") except ImportError as e: print(f"❌ Could not import app.py: {e}") except Exception as e: print(f"❌ Error launching app: {e}")