generated from bananaml/serverless-template-stable-diffusion
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.py
31 lines (22 loc) · 741 Bytes
/
server.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
from sanic import Sanic, response
import subprocess
import app as user_src
user_src.init()
server = Sanic("my_app")
@server.route('/healthcheck', methods=["GET"])
def healthcheck(request):
gpu = False
out = subprocess.run("nvidia-smi", shell=True)
if out.returncode == 0: # success state on shell command
gpu = True
return response.json({"state": "healthy", "gpu": gpu})
@server.route('/', methods=["POST"])
def inference(request):
try:
model_inputs = response.json.loads(request.json)
except:
model_inputs = request.json
output = user_src.inference(model_inputs)
return response.json(output)
if __name__ == '__main__':
server.run(host='0.0.0.0', port="8000", workers=1)