Spaces:
Sleeping
Sleeping
| from flask import Flask | |
| from flask_socketio import SocketIO | |
| from app.config import Config | |
| import os | |
| # Create SocketIO instance globally | |
| socketio = SocketIO() | |
| def create_app(config_class=Config): | |
| app = Flask(__name__) | |
| app.config.from_object(config_class) | |
| # IMPORTANT: Set a strong secret key for sessions | |
| app.secret_key = os.environ.get('SECRET_KEY') or os.urandom(24) | |
| # Ensure upload directories exist | |
| os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) | |
| os.makedirs(app.config['OUTPUT_FOLDER'], exist_ok=True) | |
| # Initialize SocketIO with proper configuration for Hugging Face Spaces | |
| socketio.init_app( | |
| app, | |
| cors_allowed_origins="*", | |
| async_mode='threading', # Changed from eventlet | |
| logger=True, | |
| engineio_logger=True, | |
| ping_timeout=60, | |
| ping_interval=25 | |
| ) | |
| # Register blueprints | |
| from app.routes import dashboard_bp, setup_bp | |
| app.register_blueprint(dashboard_bp) | |
| app.register_blueprint(setup_bp, url_prefix='/setup') | |
| return app |