Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223247 unmodified lines32333435from fastapi import FastAPIfrom contextlib import asynccontextmanagerfrom code_name_suggester import get_suggestersuggester = None@asynccontextmanagerasync def lifespan(app: FastAPI):global suggesterprint("🚀 加载模型...")suggester = get_suggester("KyrieChao/code-method-namer", device="cpu")print("✅ 模型加载完成")yieldapp = FastAPI(title="Code Method Namer API",lifespan=lifespan)@app.post("/predict")async def predict(payload: dict):code = payload.get("code", "").strip()if not code:return {"error": "code is required"}7 unmodified lines}names = suggester.suggest(processed, num_candidates=3)return {"suggestions": names}12345678910111213141516177 unmodified lines2526272829from fastapi import FastAPIfrom code_name_suggester import get_suggesterapp = FastAPI(title="Code Method Namer API")suggester = None@app.post("/predict")async def predict(payload: dict):global suggesterif suggester is None:suggester = get_suggester("KyrieChao/code-method-namer", device="cpu")code = payload.get("code", "").strip()if not code:return {"error": "code is required"}7 unmodified lines}names = suggester.suggest(processed, num_candidates=3)return {"suggestions": names}
app.py+7-13