maartengr / ml-api Goto Github PK
View Code? Open in Web Editor NEWGuide on creating an API for serving your ML model
Guide on creating an API for serving your ML model
First thanks for your great article in Medium!
I have a problem when implementing your code.
I use your test code as test_api.py
:
import requests
to_predict_dict = {'satisfaction_level': 0.38,
'last_evaluation': 0.53,
'number_project': 2,
'average_montly_hours': 157,
'time_spend_company': 3,
'Work_accident': 0,
'promotion_last_5years': 0,
'sales': 'support',
'salary': 'low'}
url = 'http://127.0.0.1:8000/predict'
r = requests.post(url, json=to_predict_dict)
print(r.json())
It return prediction after excuting.
$ python test_api.py
{'prediction': 1}
And the server log seems work well
INFO: 127.0.0.1:49703 - "POST /predict HTTP/1.1" 200 OK
But when I use the Swagger interface, it returns {"detail":"There was an error parsing the body"}
ใ
Using the curl is the same error.
$ curl -X POST "http://127.0.0.1:8000/predict" -H "accept: application/json" -H "Content-Type: application/json; charset=UTF-8" -d "{'satisfaction_level': 0.38, 'last_evaluation': 0.53, 'number_project': 2, 'average_montly_hours': 157, 'time_spend_company': 3, 'Work_accident': 0, 'promotion_last_5years': 0, 'sales': 'support', 'salary': 'low'}"
{"detail":"There was an error parsing the body"}%
Where is the problem and how to solve it?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.