-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate CLI into
cnlpt
command (#218)
* consolidate cli * change --model to --model_type, lazy load fastapi apps
- Loading branch information
1 parent
e04edbd
commit 912713d
Showing
21 changed files
with
153 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import click | ||
|
||
from .. import __version__ | ||
from .rest import rest_command | ||
|
||
|
||
@click.group(invoke_without_command=True) | ||
@click.option( | ||
"--version", | ||
type=bool, | ||
is_flag=True, | ||
default=False, | ||
help="Print the cnlp_transformers version.", | ||
) | ||
@click.pass_context | ||
def cli(ctx: click.Context, version: bool): | ||
if ctx.invoked_subcommand is not None: | ||
return | ||
|
||
if version: | ||
print(__version__) | ||
ctx.exit() | ||
else: | ||
click.echo(ctx.get_help()) | ||
ctx.exit() | ||
|
||
|
||
cli.add_command(rest_command) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import click | ||
|
||
from ..api import MODEL_TYPES, get_rest_app | ||
|
||
|
||
@click.command("rest", context_settings={"show_default": True}) | ||
@click.option( | ||
"--model-type", | ||
type=click.Choice(MODEL_TYPES), | ||
required=True, | ||
) | ||
@click.option( | ||
"-h", | ||
"--host", | ||
type=str, | ||
default="0.0.0.0", | ||
help="Host address to serve the REST app.", | ||
) | ||
@click.option( | ||
"-p", "--port", type=int, default=8000, help="Port to serve the REST app." | ||
) | ||
@click.option( | ||
"--reload", | ||
type=bool, | ||
is_flag=True, | ||
default=False, | ||
help="Auto-reload the REST app.", | ||
) | ||
def rest_command(model_type: str, host: str, port: int, reload: bool): | ||
"""Start a REST application from a model.""" | ||
import uvicorn | ||
|
||
uvicorn.run(get_rest_app(model_type), host=host, port=port, reload=reload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
MODEL_TYPES = ( | ||
"cnn", | ||
"current", | ||
"dtr", | ||
"event", | ||
"hier", | ||
"negation", | ||
"temporal", | ||
"termexists", | ||
"timex", | ||
) | ||
|
||
|
||
def get_rest_app(model_type: str): | ||
if model_type == "cnn": | ||
from .cnn_rest import app | ||
|
||
return app | ||
elif model_type == "current": | ||
from .current_rest import app | ||
|
||
return app | ||
elif model_type == "dtr": | ||
from .dtr_rest import app | ||
|
||
return app | ||
elif model_type == "event": | ||
from .event_rest import app | ||
|
||
return app | ||
elif model_type == "hier": | ||
from .hier_rest import app | ||
|
||
return app | ||
elif model_type == "negation": | ||
from .negation_rest import app | ||
|
||
return app | ||
elif model_type == "temporal": | ||
from .temporal_rest import app | ||
|
||
return app | ||
elif model_type == "termexists": | ||
from .termexists_rest import app | ||
|
||
return app | ||
elif model_type == "timex": | ||
from .timex_rest import app | ||
|
||
return app | ||
else: | ||
raise ValueError(f"unknown model type: {model_type}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.