Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

diamond_predict_api.py 932 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  1. # -*- coding: utf-8 -*-
  2. import pandas as pd
  3. from pycaret.regression import load_model, predict_model
  4. from fastapi import FastAPI
  5. import uvicorn
  6. from pydantic import create_model
  7. # Create the app
  8. app = FastAPI()
  9. # Load trained Pipeline
  10. model = load_model("diamond_predict_api")
  11. # Create input/output pydantic models
  12. input_model = create_model("diamond_predict_api_input", **{'Carat Weight': 1.149999976158142, 'Cut': 'Ideal', 'Color': 'H', 'Clarity': 'SI1', 'Polish': 'VG', 'Symmetry': 'VG', 'Report': 'GIA'})
  13. output_model = create_model("diamond_predict_api_output", prediction=5169)
  14. # Define predict function
  15. @app.post("/predict", response_model=output_model)
  16. def predict(data: input_model):
  17. data = pd.DataFrame([data.dict()])
  18. predictions = predict_model(model, data=data)
  19. return {"prediction": predictions["prediction_label"].iloc[0]}
  20. if __name__ == "__main__":
  21. uvicorn.run(app, host="0.0.0.0", port=8000)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...