nivedithahn96 commited on
Commit
cb57c0c
·
verified ·
1 Parent(s): 93a460c

Create serve.py

Browse files
Files changed (1) hide show
  1. serve.py +21 -0
serve.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json, os
2
+ from fastapi import FastAPI, Request
3
+ from handler import EndpointHandler
4
+
5
+ app = FastAPI()
6
+ _handler = EndpointHandler(path=os.environ.get("MODEL_DIR", "/repository"))
7
+
8
+ @app.get("/health")
9
+ def health():
10
+ return {"status": "ok"}
11
+
12
+ @app.post("/")
13
+ async def predict(request: Request):
14
+ content_type = request.headers.get("content-type", "")
15
+ if "application/json" in content_type:
16
+ data = await request.json()
17
+ else:
18
+ body = await request.body()
19
+ params = json.loads(request.headers.get("x-parameters", "{}"))
20
+ data = {"inputs": body, "parameters": params}
21
+ return _handler(data)