Spaces:
Sleeping
Sleeping
File size: 2,078 Bytes
a156dd1 |
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 |
#!/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}") |