Skip to content

Commit

Permalink
Make osam serve optional
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jul 30, 2024
1 parent 497345b commit df960ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions osam/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import imgviz
import numpy as np
import PIL.Image
import uvicorn
from loguru import logger

from . import __version__
Expand Down Expand Up @@ -97,8 +96,15 @@ def rm(model_name):
@cli.command(help="Start server")
@click.option("--reload", is_flag=True, help="reload server on file changes")
def serve(reload):
logger.info("Starting server...")
uvicorn.run("osam._server:app", host="127.0.0.1", port=11368, reload=reload)
try:
import uvicorn
import osam._server

logger.info("Starting server...")
uvicorn.run("osam._server:app", host="127.0.0.1", port=11368, reload=reload)
except ImportError:
logger.error("Run `pip install osam[serve]` to use `osam serve`")
sys.exit(1)


@cli.command(help="Run a model")
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ classifiers = [
dependencies = [
"click",
"gdown",
"fastapi",
"imgviz",
"loguru",
"onnxruntime",
"Pillow",
"pydantic",
"uvicorn",
]
dynamic = ["readme", "version"]

[project.optional-dependencies]
serve = [
"fastapi",
"uvicorn",
]
test = [
"build",
"mypy",
Expand Down

0 comments on commit df960ea

Please sign in to comment.