Skip to content

Instantly share code, notes, and snippets.

@MachineLearningIsEasy
Created November 3, 2021 12:28
Show Gist options
  • Save MachineLearningIsEasy/7659594a93de718a404891d024967e28 to your computer and use it in GitHub Desktop.
Save MachineLearningIsEasy/7659594a93de718a404891d024967e28 to your computer and use it in GitHub Desktop.
Flask model API
from flask import request, Flask
import json
import pickle
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def main_flask_function():
if request.method == 'GET':
return 'Use post method'
else:
req_data = json.loads(request.data)
print(list(req_data.values()))
with open('clf_wine.pickle', 'rb') as f:
clf_new = pickle.load(f)
print( list( map(int, clf_new.predict( [list(req_data.values())] ) ) ) )
return {'prediction':list(map(int,clf_new.predict([list(req_data.values())])))}
if __name__ == '__main__':
app.run(host = '0.0.0.0',debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment