HelloSun commited on
Commit
d41bb35
·
verified ·
1 Parent(s): c920340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -6,7 +6,7 @@ import fcntl
6
  import termios
7
  import asyncio
8
  import json
9
- import spaces # 导入 spaces
10
  from fastapi import FastAPI, WebSocket, WebSocketDisconnect
11
  from fastapi.responses import HTMLResponse
12
  import uvicorn
@@ -151,15 +151,15 @@ createTab();
151
  async def index():
152
  return HTMLResponse(HTML_PAGE)
153
 
154
- # ---- 满足 ZeroGPU 要求的空函数,仅启动时调用一次 ----
155
- @spaces.GPU
156
  async def dummy_gpu():
157
- """空函数,仅用于让平台检测到 GPU 装饰器,调用一次后不再使用"""
158
  return
159
 
160
  @app.on_event("startup")
161
  async def startup_event():
162
- # 启动时调用一次,确保平台识别到 GPU 使用,但不会持续消耗
163
  await dummy_gpu()
164
 
165
  @app.websocket("/ws")
 
6
  import termios
7
  import asyncio
8
  import json
9
+ import spaces
10
  from fastapi import FastAPI, WebSocket, WebSocketDisconnect
11
  from fastapi.responses import HTMLResponse
12
  import uvicorn
 
151
  async def index():
152
  return HTMLResponse(HTML_PAGE)
153
 
154
+ # 带 duration 参数的装饰器,duration 设定为 1 秒,仅用于启动时的一次性调用
155
+ @spaces.GPU(duration=1)
156
  async def dummy_gpu():
157
+ """空函数,仅用于让平台识别到 GPU 装饰器"""
158
  return
159
 
160
  @app.on_event("startup")
161
  async def startup_event():
162
+ # 启动时调用一次,消耗约 1 秒的 GPU 时间(实际几乎无计算量)
163
  await dummy_gpu()
164
 
165
  @app.websocket("/ws")