Skip to content

Instantly share code, notes, and snippets.

@sai-sondarkar
Last active September 5, 2019 23:12
Show Gist options
  • Save sai-sondarkar/c031a282ab459e410c65884cc4954c14 to your computer and use it in GitHub Desktop.
Save sai-sondarkar/c031a282ab459e410c65884cc4954c14 to your computer and use it in GitHub Desktop.
from flask import Flask, request, redirect, url_for, flash, jsonify
import numpy as np
import pickle as p
import json
app = Flask(__name__)
@app.route('/api/', methods=['POST'])
def makecalc():
data = request.get_json()
prediction = np.array2string(model.predict(data))
return jsonify(prediction)
if __name__ == '__main__':
modelfile = 'final_prediction.pickle'
model = p.load(open(modelfile, 'rb'))
app.run(debug=True, host='0.0.0.0')
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import requests
import json
url = 'http://0.0.0.0:5000/api/'
data = [[14.34, 1.68, 2.7, 25.0, 98.0, 2.8, 1.31, 0.53, 2.7, 13.0, 0.57, 1.96, 660.0]]
j_data = json.dumps(data)
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
r = requests.post(url, data=j_data, headers=headers)
print(r, r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment