Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make osam serve optional by pip install osam[serve] #22

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 10 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,16 @@ 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 # noqa: F401

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
Loading