Skip to content

Commit

Permalink
add comments to deploy-ml-model/app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Jha authored and Aditya Jha committed Nov 1, 2023
1 parent 49dc1c5 commit 27e6405
Showing 1 changed file with 6 additions and 1 deletion.
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}

0 comments on commit 27e6405

Please sign in to comment.