|
@@ -1,10 +1,9 @@
|
|
|
|
|
+#!/usr/bin/env python
|
|
|
|
|
|
|
|
import gunicorn.app.base
|
|
import gunicorn.app.base
|
|
|
|
|
+import sys
|
|
|
from predictor import Predictor, Prediction
|
|
from predictor import Predictor, Prediction
|
|
|
|
|
|
|
|
-HOST_PORT = "localhost:8001"
|
|
|
|
|
-MODEL = "cells_2.pth"
|
|
|
|
|
-
|
|
|
|
|
class CustomUnicornApp(gunicorn.app.base.BaseApplication):
|
|
class CustomUnicornApp(gunicorn.app.base.BaseApplication):
|
|
|
"""
|
|
"""
|
|
|
This gunicorn app class provides create and exit callbacks for workers,
|
|
This gunicorn app class provides create and exit callbacks for workers,
|
|
@@ -96,7 +95,7 @@ from bottle import Bottle, request, response
|
|
|
import threading
|
|
import threading
|
|
|
import io
|
|
import io
|
|
|
|
|
|
|
|
-def startServer(index_html:str, predictor:Predictor):
|
|
|
|
|
|
|
+def startServer(index_html:str, predictor:Predictor, host_port:str):
|
|
|
def create():
|
|
def create():
|
|
|
app = Bottle()
|
|
app = Bottle()
|
|
|
lock = threading.Lock()
|
|
lock = threading.Lock()
|
|
@@ -130,9 +129,20 @@ def startServer(index_html:str, predictor:Predictor):
|
|
|
# Get the service through the app object and save state
|
|
# Get the service through the app object and save state
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
- CustomUnicornApp(create, exit, HOST_PORT).run()
|
|
|
|
|
|
|
+ CustomUnicornApp(create, exit, host_port).run()
|
|
|
|
|
+
|
|
|
|
|
+def usage():
|
|
|
|
|
+ print("""Usage:
|
|
|
|
|
+ server.py modelfile host_port
|
|
|
|
|
+
|
|
|
|
|
+Example:
|
|
|
|
|
+ ./server.py cells_2.pth localhost:8001
|
|
|
|
|
+""")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- p = Predictor(MODEL)
|
|
|
|
|
- startServer(html, p)
|
|
|
|
|
|
|
+ if len(sys.argv) != 3:
|
|
|
|
|
+ usage()
|
|
|
|
|
+ else:
|
|
|
|
|
+ p = Predictor(sys.argv[1])
|
|
|
|
|
+ startServer(html, p, sys.argv[2])
|
|
|
|
|
|