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

Feature/server containerization #26

Merged
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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ python fastserve.deploy.lightning --filename main.py \
--machine "CPU" # T4, A10G or A10G_X_4
```

## Containerization

To containerize your FastServe application, a Docker example is provided in the `examples/docker-compose-example` directory. The example is about face recognition and includes a `Dockerfile` for creating a Docker image and a `docker-compose.yml` for easy deployment. Here's a quick overview:

- **Dockerfile**: Defines the environment, installs dependencies from `requirements.txt`, and specifies the command to run your FastServe application.
- **docker-compose.yml**: Simplifies the deployment of your FastServe application by defining services, networks, and volumes.

To use the example, navigate to the `examples/docker-compose-example` directory and run:

```shell
docker-compose up --build
```

This will build the Docker image and start your FastServe application in a container, making it accessible on the specified port.

Note: We provide an example using face recognition. If you need to use other models, you will likely need to change the requirements.txt or the Dockerfile. Don't worry; this example is intended to serve as a quick start. Feel free to modify it as needed.

## Passing Arguments to Uvicorn in `run_server()`
FastServe leverages Uvicorn, a lightning-fast ASGI server, to serve machine learning models, making FastServe highly efficient and scalable.
The `run_server()` method supports passing additional arguments to uvicorn by utilizing `*args` and `**kwargs`. This feature allows you to customize the server's behavior without modifying the source code. For example:

```shell
app.run_server(host='0.0.0.0', port=8000, log_level='info')
```

In this example, host, port, and log_level are passed directly to uvicorn.run() to specify the server's IP address, port, and logging level. You can pass any argument supported by `uvicorn.run()` to `run_server()` in this manner.

## Contribute

**Install in editable mode:**
Expand Down
15 changes: 15 additions & 0 deletions examples/docker-compose-example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11

WORKDIR /api

# Copying requirements.txt to the container's working directory
COPY requirements.txt .

# Copying all other files and directories to the container's working directory
COPY . /api

# Installing dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Running the api
CMD ["python", "api.py"]
11 changes: 11 additions & 0 deletions examples/docker-compose-example/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from fastserve.models import FaceDetection

# example of getting environment variables setted in docker-compose.yml
batch_size = os.environ.get("BATCH_SIZE", 2)
timeout = os.environ.get("TIMEOUT", 1)


app = FaceDetection(batch_size=batch_size, timeout=timeout)
app.run_server(host="0.0.0.0")
11 changes: 11 additions & 0 deletions examples/docker-compose-example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'
services:
api:
build: .
environment:
- BATCH_SIZE=2
- TIMEOUT = 1
volumes:
- .:/api
ports:
- "8000:8000"
3 changes: 3 additions & 0 deletions examples/docker-compose-example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git+https://github.com/aniketmaurya/fastserve-ai.git
torch
face-recognition
Loading