Skip to content

Instantly share code, notes, and snippets.

Created April 23, 2021 21:11
What would you like to do?
# 1. Library imports
import pandas as pd
from pycaret.regression import load_model, predict_model
from fastapi import FastAPI
import uvicorn
# 2. Create the app object
app = FastAPI()
#. Load trained Pipeline
model = load_model('diamond-pipeline')
# Define predict function'/predict')
def predict(carat_weight, cut, color, clarity, polish, symmetry, report):
data = pd.DataFrame([[carat_weight, cut, color, clarity, polish, symmetry, report]])
data.columns = ['Carat Weight', 'Cut', 'Color', 'Clarity', 'Polish', 'Symmetry', 'Report']
predictions = predict_model(model, data=data)
return {'prediction': int(predictions['Label'][0])}
if __name__ == '__main__':, host='', port=8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment