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 bcecd20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
pip install osam
```

**For `osam serve`**:

```bash
pip install osam[serve]
```

## Quickstart

To run with EfficientSAM:
Expand Down Expand Up @@ -102,6 +108,8 @@ PIL.Image.fromarray(response.mask).save("mask.png")
### HTTP

```bash
# pip install osam[serve] # required for `osam serve`

# Get up the server
osam serve

Expand Down
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 bcecd20

Please sign in to comment.