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

api_for_existing_model.py 800 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
  1. # 1. Library imports
  2. import pandas as pd
  3. from pycaret.regression import load_model, predict_model
  4. from fastapi import FastAPI
  5. import uvicorn
  6. # 2. Create the app object
  7. app = FastAPI()
  8. #. Load trained Pipeline
  9. model = load_model('diamond_predict_api')
  10. # Define predict function
  11. @app.post('/predict')
  12. def predict(carat_weight, cut, color, clarity, polish, symmetry, report):
  13. data = pd.DataFrame([[carat_weight, cut, color, clarity, polish, symmetry, report]])
  14. data.columns = ['Carat Weight', 'Cut', 'Color', 'Clarity', 'Polish', 'Symmetry', 'Report']
  15. predictions = predict_model(model, data=data)
  16. return {'prediction': int(predictions['Label'][0])}
  17. if __name__ == '__main__':
  18. uvicorn.run(app, host='127.0.0.1', port=8000)
  19. # http://localhost:8000/docs
Tip!

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

Comments

Loading...