Spaces:
Sleeping
Sleeping
| #!/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}") |