""" SeedDream v4 Editor - 简化版本 重构后的干净架构,消除过度复杂性 """ import os from pathlib import Path from flask import Flask, render_template, send_from_directory from flask_cors import CORS from api.routes import api def create_app(): """创建Flask应用 - 简化配置""" app = Flask(__name__) CORS(app) # 简化配置 app.config.update({ 'MAX_CONTENT_LENGTH': 16 * 1024 * 1024, # 16MB 'UPLOAD_FOLDER': '/tmp' }) # 确保目录存在 Path("static").mkdir(exist_ok=True) Path("templates").mkdir(exist_ok=True) # 注册API蓝图 app.register_blueprint(api, url_prefix='/api') # 主路由 @app.route('/') def index(): return render_template('index.html') @app.route('/static/') def serve_static(filename): return send_from_directory('static', filename) return app if __name__ == '__main__': app = create_app() # 获取端口配置 port = int(os.environ.get('PORT', 7860)) is_production = os.environ.get('SPACE_ID') is not None # 启动应用 app.run( host='0.0.0.0', port=port, debug=not is_production )