Skip to content

Commit

Permalink
added uvicorn params
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhal baccouri committed Jun 18, 2021
1 parent 7178c8e commit 4b74224
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions igel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class CLI:
"model": "model_name",
"type": "model_type",
"tg": "target",
# host and port for serving the model
"h": "host",
"p": "port",
}

def __init__(self):
Expand Down Expand Up @@ -570,10 +573,19 @@ def serve(self):
"""
expose a REST endpoint in order to use the trained ML model
"""
os.environ[Constants.model_results_path] = self.dict_args[
"model_results_dir"
]
fastapi_server.run()
try:
os.environ[Constants.model_results_path] = self.dict_args[
"model_results_dir"
]
uvicorn_params = {}
if "host" in self.dict_args and "port" in self.dict_args:
uvicorn_params["host"] = self.dict_args.get("host")
uvicorn_params["port"] = int(self.dict_args.get("port"))

fastapi_server.run(**uvicorn_params)

except Exception as ex:
logger.exception(ex)

def _tableize(self, df):
"""
Expand Down
2 changes: 1 addition & 1 deletion igel/servers/fastapi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def predict(data: dict = Body(...)):

def run(**kwargs):

uvicorn.run(app)
uvicorn.run(app, **kwargs)


if __name__ == "__main__":
Expand Down

0 comments on commit 4b74224

Please sign in to comment.