ChaseHan commited on
Commit
eafb78b
·
verified ·
1 Parent(s): 6add7e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -12,6 +12,18 @@ from config import DEBUG_MODE
12
  from fastapi import FastAPI
13
  from fastapi.responses import JSONResponse
14
  import json
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  def ensure_assets_directory():
17
  """确保assets目录存在并包含必要的静态文件"""
@@ -137,7 +149,14 @@ class AppState:
137
  app_state = AppState()
138
 
139
  # CreateFastAPI应用
140
- app = FastAPI()
 
 
 
 
 
 
 
141
 
142
  # 修改 FastAPI 路由部分
143
  @app.post("/trigger_llm")
@@ -1238,7 +1257,7 @@ def create_interface():
1238
  outputs=[expanded_concept_section, concepts_section]
1239
  )
1240
 
1241
- # 添加FastAPI集成
1242
  gr.mount_gradio_app(app, demo, path="/")
1243
 
1244
  return demo
@@ -1246,4 +1265,23 @@ def create_interface():
1246
  if __name__ == "__main__":
1247
  demo = create_interface()
1248
 
1249
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  from fastapi import FastAPI
13
  from fastapi.responses import JSONResponse
14
  import json
15
+ from fastapi.staticfiles import StaticFiles
16
+ import matplotlib as mpl
17
+ import platform
18
+
19
+ # 设置中文字体
20
+ if platform.system() == "Linux":
21
+ # Linux系统使用文泉驿微米黑
22
+ mpl.rcParams['font.sans-serif'] = ['WenQuanYi Micro Hei']
23
+ else:
24
+ # Windows系统使用微软雅黑
25
+ mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei']
26
+ mpl.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
27
 
28
  def ensure_assets_directory():
29
  """确保assets目录存在并包含必要的静态文件"""
 
149
  app_state = AppState()
150
 
151
  # CreateFastAPI应用
152
+ app = FastAPI(
153
+ title="Educational LLM Assistant",
154
+ description="Interactive Learning Through AI-Powered Concept Breakdown",
155
+ version="1.0.0"
156
+ )
157
+
158
+ # 添加静态文件服务
159
+ app.mount("/assets", StaticFiles(directory="assets"), name="assets")
160
 
161
  # 修改 FastAPI 路由部分
162
  @app.post("/trigger_llm")
 
1257
  outputs=[expanded_concept_section, concepts_section]
1258
  )
1259
 
1260
+ # 挂载Gradio应用
1261
  gr.mount_gradio_app(app, demo, path="/")
1262
 
1263
  return demo
 
1265
  if __name__ == "__main__":
1266
  demo = create_interface()
1267
 
1268
+ # 修改启动配置
1269
+ demo.launch(
1270
+ server_name="0.0.0.0", # 允许外部访问
1271
+ server_port=7860, # 使用标准端口
1272
+ share=False, # 在HF空间中不需要share
1273
+ favicon_path=None, # 禁用favicon
1274
+ show_api=False, # 禁用API文档
1275
+ show_error=True, # 显示详细错误信息
1276
+ quiet=True, # 减少日志输出
1277
+ ssl_verify=False, # 禁用SSL验证
1278
+ ssl_keyfile=None,
1279
+ ssl_certfile=None,
1280
+ ssl_keyfile_password=None,
1281
+ ssl_verify_peer=False,
1282
+ root_path="", # 清空root_path
1283
+ app_kwargs={
1284
+ "static_dir": "assets", # 指定静态文件目录
1285
+ "static_url_path": "/assets", # 指定静态文件URL路径
1286
+ }
1287
+ )