donotthink commited on
Commit
418cd34
·
verified ·
1 Parent(s): aa348d3

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -106,13 +106,23 @@ if _font_src.exists():
106
  shutil.copy2(_f, _font_dst / _f.name)
107
  subprocess.run(["fc-cache", "-fv"], capture_output=True)
108
 
109
- # ---- ZeroGPU 兼容层:必须有 @spaces.GPU 装饰的函数,否则 ZeroGPU 会停止应用 ----
110
  import spaces
 
111
 
112
  @spaces.GPU
113
  def _zero_gpu_warmup():
114
- """占位函数,让 ZeroGPU 检测到 GPU 函数。实际不使用 GPU。"""
115
- return None
 
 
 
 
 
 
 
 
 
116
 
117
  # ---- 启动 meme_generator 原生 FastAPI(无 Gradio,无 CSRF)----
118
  import uvicorn
 
106
  shutil.copy2(_f, _font_dst / _f.name)
107
  subprocess.run(["fc-cache", "-fv"], capture_output=True)
108
 
109
+ # ---- ZeroGPU 兼容层:必须有 @spaces.GPU 装饰的函数并实际调用,否则 ZeroGPU 会停止应用 ----
110
  import spaces
111
+ import asyncio
112
 
113
  @spaces.GPU
114
  def _zero_gpu_warmup():
115
+ """占位函数,让 ZeroGPU 检测到 GPU 函数调用。实际不使用 GPU。"""
116
+ return "warmup-ok"
117
+
118
+ # 启动前实际调用一次,触发 spaces 库的 GPU 初始化
119
+ try:
120
+ _r = _zero_gpu_warmup()
121
+ if asyncio.iscoroutine(_r):
122
+ asyncio.run(_r)
123
+ print("[zero-gpu] warmup done", flush=True)
124
+ except Exception as _e:
125
+ print(f"[zero-gpu] warmup skipped: {_e}", flush=True)
126
 
127
  # ---- 启动 meme_generator 原生 FastAPI(无 Gradio,无 CSRF)----
128
  import uvicorn