Skip to content

Instantly share code, notes, and snippets.

@MarwanDebbiche
Created August 8, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarwanDebbiche/8b4eeefab08444950b1cb3490fe057ae to your computer and use it in GitHub Desktop.
Save MarwanDebbiche/8b4eeefab08444950b1cb3490fe057ae to your computer and use it in GitHub Desktop.
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