bytedance-1 / run_app.py
drdata's picture
Upload folder using huggingface_hub
3402506 verified
#!/usr/bin/env python3
"""
Helper script to run the BytePlus Image Generation Studio
This ensures the proper directories are created and accessible
"""
import os
import sys
import subprocess
from pathlib import Path
def setup_directories():
"""Ensure all required directories exist and are accessible"""
cache_dir = Path(".cache")
# Required directories
directories = [
cache_dir / "Generated",
cache_dir / "static",
cache_dir / "view_session"
]
print("Setting up directories...")
for directory in directories:
directory.mkdir(parents=True, exist_ok=True)
print(f"βœ… Created/verified: {directory}")
# Fix cache directory permissions if needed
try:
cache_dir.chmod(0o755)
print("βœ… Fixed cache directory permissions")
except Exception as e:
print(f"⚠️ Could not fix permissions: {e}")
# Create symbolic links for easy access
main_dir = Path(".")
links = [
("Generated", cache_dir / "Generated"),
("static", cache_dir / "static"),
("view_session", cache_dir / "view_session")
]
for link_name, target in links:
link_path = main_dir / link_name
if link_path.exists() or link_path.is_symlink():
if link_path.is_symlink():
link_path.unlink()
elif link_path.is_dir():
# If it's a directory, rename it to backup
backup_name = f"{link_name}_backup"
link_path.rename(main_dir / backup_name)
print(f"πŸ“ Backed up existing directory to {backup_name}")
try:
link_path.symlink_to(target)
print(f"πŸ”— Created symlink: {link_name} -> {target}")
except Exception as e:
print(f"⚠️ Could not create symlink {link_name}: {e}")
def run_app():
"""Run the downloaded application"""
cache_dir = Path(".cache")
app_file = cache_dir / "app.py"
if not app_file.exists():
print("❌ App file not found. Please run the main app.py first to download the space.")
return False
print(f"πŸš€ Starting application from {app_file}")
print("πŸ“ Generated images will be stored in: ./Generated/")
print("🌐 Static files will be served from: ./static/")
print("πŸ‘οΈ Session viewer will be available at: /view_session/")
print("-" * 50)
# Change to cache directory and run the app
os.chdir(cache_dir)
try:
subprocess.run([sys.executable, "app.py"], check=True)
except KeyboardInterrupt:
print("\n⏹️ Application stopped by user")
except Exception as e:
print(f"❌ Error running application: {e}")
return False
return True
if __name__ == "__main__":
print("πŸ”§ BytePlus Image Generation Studio - Setup & Run")
print("=" * 50)
setup_directories()
print("\n" + "=" * 50)
if len(sys.argv) > 1 and sys.argv[1] == "--setup-only":
print("βœ… Setup complete. Directories are now accessible.")
print("To run the app: python run_app.py")
else:
run_app()