-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastapi_server.py
More file actions
87 lines (75 loc) · 2.14 KB
/
Copy pathfastapi_server.py
File metadata and controls
87 lines (75 loc) · 2.14 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
智慧教室 FastAPI服务器
集成LLM语音助手功能
"""
from fastapi import FastAPI, HTTPException
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import logging
import os
# 配置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# 创建FastAPI应用
app = FastAPI(
title="智慧教室控制系统",
description="集成LLM语音助手的智慧教室控制系统",
version="2.0.0"
)
# 配置CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 挂载静态文件目录
app.mount("/static", StaticFiles(directory="FrontPanel"), name="static")
# 延迟导入路由
@app.on_event("startup")
async def startup_event():
"""启动事件"""
from voice_api import router as voice_router
from api_routes import router as api_router
# 注册路由
app.include_router(api_router, prefix="/api")
app.include_router(voice_router, prefix="/api")
logger.info("🚀 智慧教室控制系统启动")
logger.info("🎯 LLM语音助手已初始化")
logger.info("📱 前端地址: http://localhost:8000/static/index.html")
@app.on_event("shutdown")
async def shutdown_event():
"""关闭事件"""
logger.info("🔌 系统正在关闭...")
@app.get("/")
async def root():
"""根路由"""
return {
"message": "智慧教室控制系统已启动",
"version": "2.0.0",
"features": [
"LLM语音助手",
"智能环境控制",
"实时数据监控",
"用户偏好学习"
],
"endpoints": {
"frontend": "/static/index.html",
"voice_api": "/api/voice/command",
"health": "/api/voice/health"
}
}
@app.get("/health")
async def health_check():
"""健康检查"""
return {"status": "healthy", "service": "smart_classroom_system"}
if __name__ == "__main__":
uvicorn.run(
"fastapi_server:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level="info"
)