Spaces:
Runtime error
Runtime error
| """ | |
| 启动脚本 - 同时运行 Gradio UI 和 FastAPI | |
| """ | |
| import asyncio | |
| import threading | |
| import uvicorn | |
| from app import create_ui | |
| from api import app as fastapi_app | |
| def run_fastapi(): | |
| """在后台线程运行 FastAPI""" | |
| uvicorn.run(fastapi_app, host="0.0.0.0", port=8000, log_level="info") | |
| if __name__ == "__main__": | |
| # 启动 FastAPI 后台线程 | |
| api_thread = threading.Thread(target=run_fastapi, daemon=True) | |
| api_thread.start() | |
| print("✅ FastAPI started on port 8000") | |
| print("📚 API docs: http://localhost:8000/api/docs") | |
| # 启动 Gradio(主线程) | |
| demo = create_ui() | |
| demo.launch( | |
| server_name="0.0.0.0", | |
| server_port=7860, | |
| share=False | |
| ) | |