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

add comments to deploy-ml-model/app.py #11

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion deploy-ml-model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
import pandas as pd
from fastapi import FastAPI

# Load the pre-trained machine learning model
model = joblib.load("iris_classifier.joblib")

# Create a FastAPI app instance with custom configuration
app = FastAPI(docs_url="/", root_path=os.getenv("TFY_SERVICE_ROOT_PATH", "/"))


# Define an API endpoint for making predictions
@app.post("/predict")
def predict(
sepal_length: float, sepal_width: float, petal_length: float, petal_width: float
):
# Create a dictionary with input data
data = dict(
sepal_length=sepal_length,
sepal_width=sepal_width,
petal_length=petal_length,
petal_width=petal_width,
)
# Make a prediction using the loaded model
prediction = int(model.predict(pd.DataFrame([data]))[0])
# Return the prediction as a JSON response
return {"prediction": prediction}