-
Notifications
You must be signed in to change notification settings - Fork 1
/
http_api.py
42 lines (29 loc) · 800 Bytes
/
http_api.py
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
41
import uvicorn
import subprocess
from fastapi import FastAPI
from pydantic import BaseModel
import app as user_model
from decorators import logger
# init model first
user_model.init()
class PromptInput(BaseModel):
context: str = ""
question: str = ""
http_api = FastAPI()
@http_api.get("/healthcheck")
async def healthcheck():
gpu = False
out = subprocess.run("nvidia-smi", shell=True)
if out.returncode == 0:
gpu = True
return {"state": "healthy", "gpu": gpu}
@http_api.post("/")
async def inference(prompt: PromptInput):
output = {}
try:
output = user_model.inference(prompt.dict())
except Exception as e:
logger.error(str(e))
return output
if __name__ == "__main__":
uvicorn.run(http_api, host="0.0.0.0", port=8000)