Fix GPU detection by adding module-level GPU request and decorator on root endpoint
Browse files189 unmodified lines1901911921931941952 unmodified lines198199200201202203204205206207208209210211212213214215189 unmodified lines# Space 起動時にバックグラウンドで初期化threading.Thread(target=initialize_model, daemon=True).start()app = FastAPI(title="LLMView Word Tree API",2 unmodified lines)@app.on_event("startup")async def startup_event():"""アプリ起動時の処理(ZeroGPU要求)"""if SPACES_AVAILABLE:try:spaces.GPU()print("[SPACE] GPU要求をstartup eventで送信しました")except Exception as e:print(f"[SPACE] GPU要求エラー: {e}")@app.get("/")def root() -> Dict[str, str]:"""簡易案内"""return {189 unmodified lines1901911921931941951961971981992002012022032042052062072 unmodified lines210211212213214215216217189 unmodified lines# Space 起動時にバックグラウンドで初期化threading.Thread(target=initialize_model, daemon=True).start()# ZeroGPU対応: モジュールレベルでGPU要求(起動時に検出されるように)if SPACES_AVAILABLE:try:# spaces.GPU() を呼び出してデコレータを取得し、ダミー関数に適用gpu_decorator = spaces.GPU()@gpu_decoratordef _gpu_request_dummy():"""GPU要求用のダミー関数(Space起動時に検出される)"""passprint("[SPACE] GPU要求をモジュールレベルで送信しました")except Exception as e:print(f"[SPACE] GPU要求エラー: {e}")app = FastAPI(title="LLMView Word Tree API",2 unmodified lines)@app.get("/")@spaces.GPU # ZeroGPU対応: root エンドポイントにも適用して起動時に検出されるようにdef root() -> Dict[str, str]:"""簡易案内"""return {
app.py+13-11