File size: 753 Bytes
052521c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""

启动脚本 - 同时运行 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
    )