Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2019 16:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Flask Iris Classifier API
from flask import Flask
from flask import request
import joblib
import pandas as pd
import json
with open("iris_classifier.joblib", "rb") as f:
iris_classifier = joblib.load(f)
with open("iris_classifier_features.joblib", "rb") as f:
iris_classifier_features = joblib.load(f)
app = Flask(__name__)
@app.route('/predict-species', methods=['POST'])
def predict_species():
flower = {}
for feature in iris_classifier_features:
flower[feature] = [request.form[feature]]
flower = pd.DataFrame(flower)
species = iris_classifier.predict(flower[iris_classifier_features])
return species[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment