Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import fcntl
|
|
| 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,15 +151,15 @@ createTab();
|
|
| 151 |
async def index():
|
| 152 |
return HTMLResponse(HTML_PAGE)
|
| 153 |
|
| 154 |
-
#
|
| 155 |
-
@spaces.GPU
|
| 156 |
async def dummy_gpu():
|
| 157 |
-
"""空函数,仅用于让平台
|
| 158 |
return
|
| 159 |
|
| 160 |
@app.on_event("startup")
|
| 161 |
async def startup_event():
|
| 162 |
-
# 启动时调用一次,
|
| 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")
|