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

app.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
27
  1. # 1. Library imports
  2. import uvicorn
  3. from fastapi import FastAPI
  4. from Model import IrisModel, IrisSpecies
  5. # 2. Create app and model objects
  6. app = FastAPI()
  7. model = IrisModel()
  8. # 3. Expose the prediction functionality, make a prediction from the passed
  9. # JSON data and return the predicted flower species with the confidence
  10. @app.post('/predict')
  11. def predict_species(iris: IrisSpecies):
  12. data = iris.dict()
  13. prediction, probability = model.predict_species(
  14. data['sepal_length'], data['sepal_width'], data['petal_length'], data['petal_width']
  15. )
  16. return {
  17. 'prediction': prediction,
  18. 'probability': probability
  19. }
  20. # 4. Run the API with uvicorn
  21. # Will run on http://127.0.0.1:8000
  22. if __name__ == '__main__':
  23. uvicorn.run(app, host='127.0.0.1', port=8000)
Tip!

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

Comments

Loading...