| """FateForge v2 — 入口 (HF Spaces Gradio SDK, 不可更名)。 |
| |
| 启动: |
| python app.py # 默认 127.0.0.1:7860 |
| set FATEFORGE_PORT=7861 && python app.py |
| """ |
| from __future__ import annotations |
|
|
| import logging |
|
|
| import gradio as gr |
| from fastapi.routing import APIRoute |
| from fastapi.staticfiles import StaticFiles |
| from starlette.routing import Mount |
|
|
| from fateforge.config import HOST, PORT, STATIC_DIR |
| from fateforge.server import cast_seed, favicon, index, read |
|
|
| |
| logging.getLogger("httpx").setLevel(logging.WARNING) |
| |
| with gr.Blocks(title="FateForge") as demo: |
| pass |
|
|
| |
| from gradio.routes import App as _GradioApp |
|
|
| _app = _GradioApp.create_app(demo) |
|
|
| |
| _fateforge_routes: list = [ |
| APIRoute("/", index, methods=["GET"], include_in_schema=False), |
| APIRoute("/favicon.ico", favicon, methods=["GET"], include_in_schema=False), |
| APIRoute("/api/cast/seed", cast_seed, methods=["POST"]), |
| APIRoute("/api/read", read, methods=["POST"]), |
| ] |
| for _i, _r in enumerate(_fateforge_routes): |
| _app.router.routes.insert(_i, _r) |
|
|
| |
| if STATIC_DIR.exists(): |
| _app.router.routes.insert( |
| len(_fateforge_routes), |
| Mount("/static", app=StaticFiles(directory=STATIC_DIR), name="fateforge_static"), |
| ) |
|
|
| |
| app = _app |
|
|
| if __name__ == "__main__": |
| demo.launch( |
| server_name=HOST, |
| server_port=PORT, |
| _app=_app, |
| ) |
|
|
|
|