Jun-04-2020, 08:18 AM
hi i experience a problem. So i deploy a model in flask
from flask import Flask, request, jsonify#--jsonify will return the data from keras.models import load_model import numpy as np import pandas as pd #creates the web service running on port 127.0.0.1:12345 and answer post requests on address of the machine/api app = Flask(__name__) model=load_model('modelfordeploy.h5') @app.route("/") def hello(): return "machine learning model APIs!" @app.route('/api', methods=['GET','POST']) def predict(): # get the json send from the post as data data=request.get_json(force=True) print (data) # i want 6 variables to make the prediction #i expected jason to have the following values predict_request=[data["accx"], data["accy"], data["accz"], data["gyrx"], data["gyry"], data["gyrz"]] print (predict_request) predict_request= np.array(predict_request) print (predict_request) type (predict_request) predict_request = np.asarray( predict_request).reshape(-1, 1, 6) pred= model.predict(predict_request) print (pred) output=[pred[0]] print (output) #take a list of dictionaries and convert them to json return jsonify(results=output) if __name__ == '__main__': app.run(port=8000, debug=True) #threaded=False)and then make a post request
import requests, json import pandas as pd import numpy as np url="http://127.0.0.1:8000/api" data= json.dumps ({"accx":0.660583, "accy":0.454468, "accz":-0.585022, "gyrx":32.366615, "gyry":27.206556, "gyrz":-23.471800}) r=requests.get(url, data) print (r.json())as I result I take back the following error. I can figure out how to fix it
Error: File "request.py", line 22, in <module>
print (r.json())
File "C:\Users\aggelos\anaconda3\envs\tensorflow_env\lib\site-packages\requests\models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\aggelos\anaconda3\envs\tensorflow_env\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\aggelos\anaconda3\envs\tensorflow_env\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\aggelos\anaconda3\envs\tensorflow_env\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
(tensorflow_env) C:\Users\aggelos\Desktop\new_try>