You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/_posts/Deploying-a-Machine-Learning-Model-as-an-API-with-FastAPI-Docker-and-Knative.md
+40-14Lines changed: 40 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,45 +13,71 @@ In this blog post, we'll address this question by walking through the process of
13
13
We'll start by wrapping our machine learning model as an API using FastAPI, a modern web framework for building APIs with Python. FastAPI offers automatic OpenAPI documentation generation and high performance, making it an excellent choice for our use case.
14
14
15
15
```python
16
-
from typing import List, Dict
16
+
import pickle
17
+
from typing import Dict, List
17
18
from fastapi import FastAPI
18
-
from pydantic import BaseModel
19
+
from pydantic import BaseModel, Field
19
20
from util.get_prediction_probabilities import get_prediction_probabilities
Next, we'll containerize our FastAPI application using Docker. Docker provides a lightweight and portable way to package applications and their dependencies into containers, ensuring consistency across different environments.
46
62
47
63
```Dockerfile
48
-
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
64
+
# Use a base image with Python installed
65
+
FROM python:3.9-slim
66
+
67
+
# Set the working directory inside the container
68
+
WORKDIR /app
69
+
70
+
# Copy the requirements file into the container
71
+
COPY requirements.txt .
49
72
50
-
COPY ./app /app
73
+
# Install the Python dependencies
74
+
RUN pip install -r requirements.txt
51
75
52
-
RUN pip install scikit-learn # Install any dependencies
0 commit comments