Spaces:
Sleeping
Sleeping
File size: 1,011 Bytes
70c3731 764adea 70c3731 764adea 70c3731 764adea 70c3731 764adea 52f884f 764adea 52f884f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | from fastapi import FastAPI, Request
import uvicorn
import sys
import os
# Add root to path so it can find inference.py
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from inference import run_inference
app = FastAPI()
@app.get("/")
async def health():
return {"status": "ok"}
@app.post("/reset")
async def reset():
# Important: The validator sometimes looks for a reset log too
print("[RESET] Environment restored", flush=True)
return {"status": "ok"}
@app.post("/predict")
async def predict(request: Request):
data = await request.json()
# run_inference now contains our sys.stdout.flush() logic
return run_inference(data)
def main():
# log_level="info" and access_log=True ensure the server doesn't
# suppress your print statements from inference.py
uvicorn.run(
"server.app:app",
host="0.0.0.0",
port=7860,
log_level="info",
access_log=True
)
if __name__ == "__main__":
main() |