View docker-compose.test.yaml
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
version: "3" | |
services: | |
fastapi-ml-quickstart: | |
build: . | |
ports: | |
- 8000:8000 | |
entrypoint: ["pytest"] |
View ci.yaml
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 GitHub action describes the continuous integration workflow for pull requests to master. | |
name: ci | |
on: | |
pull_request: | |
branches: | |
- master | |
push: | |
branches: |
View docker-compose.yaml
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
version: "3" | |
services: | |
fastapi-ml-quickstart: | |
build: . | |
ports: | |
- 8000:8000 |
View Dockerfile
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
FROM ubuntu:19.10 | |
COPY ./api /api/api | |
COPY requirements.txt /requirements.txt | |
RUN apt-get update \ | |
&& apt-get install python3-dev python3-pip -y \ | |
&& pip3 install -r requirements.txt | |
ENV PYTHONPATH=/api |
View predict_csv.py
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
import pandas as pd | |
from fastapi import File, UploadFile, HTTPException | |
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY | |
@app.post("/predict_csv") | |
def predict_csv(csv_file: UploadFile = File(...), model: Model = Depends(get_model)): | |
try: | |
df = pd.read_csv(csv_file.file).astype(float) |
View test_predict_with_wrong_input.py
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
from itertools import product | |
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY | |
@pytest.mark.parametrize( | |
"n_instances, test_data_n_features", | |
product(range(1, 10), [n for n in range(1, 20) if n != n_features]), | |
) | |
def test_predict_with_wrong_input( |
View test_predict.py
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
import pytest | |
import random | |
from starlette.testclient import TestClient | |
from starlette.status import HTTP_200_OK | |
from api.ml.model import n_features | |
@pytest.mark.parametrize("n_instances", range(1, 10)) |
View conftest.py
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
import pytest | |
from starlette.testclient import TestClient | |
from ..main import app | |
from ..ml.model import get_model | |
from .mocks import MockModel | |
def get_model_override(): |
View mocks.py
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
import numpy as np | |
class MockModel: | |
def __init__(self, model_path: str = None): | |
self._model_path = None | |
self._model = None | |
def predict(self, X: np.ndarray) -> np.ndarray: | |
n_instances = len(X) |
View predictrequest_final.py
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
from pydantic import BaseModel, ValidationError, validator | |
from .ml.model import n_features | |
class PredictRequest(BaseModel): | |
data: List[List[float]] | |
@validator("data") | |
def check_dimensionality(cls, v): |
NewerOlder