prediction endpoint - get recommeder from Flask app config - create dataframe from JSON in call - call prediction pipeline - get class id mapping - construct result
()
| 19 | |
| 20 | @predict_blueprint.route('/predict',methods=['GET','POST']) |
| 21 | def do_predict(): |
| 22 | """ |
| 23 | prediction endpoint |
| 24 | |
| 25 | - get recommeder from Flask app config |
| 26 | - create dataframe from JSON in call |
| 27 | - call prediction pipeline |
| 28 | - get class id mapping |
| 29 | - construct result |
| 30 | """ |
| 31 | input = extract_input() |
| 32 | print input |
| 33 | pw = current_app.config["seldon_pipeline_wrapper"] |
| 34 | pipeline = current_app.config["seldon_pipeline"] |
| 35 | df = pw.create_dataframe(input["json"]["data"]) |
| 36 | preds = pipeline.predict_proba(df) |
| 37 | idMap = pipeline._final_estimator.get_class_id_map() |
| 38 | formatted_recs_list=[] |
| 39 | for index, proba in enumerate(preds[0]): |
| 40 | if index in idMap: |
| 41 | indexName = idMap[index] |
| 42 | else: |
| 43 | indexName = str(index) |
| 44 | formatted_recs_list.append({ |
| 45 | "prediction": str(proba), |
| 46 | "predictedClass": indexName, |
| 47 | "confidence" : str(proba) |
| 48 | }) |
| 49 | ret = { "predictions": formatted_recs_list , "meta": {"modelName" : current_app.config['seldon_model_name']}} |
| 50 | json = jsonify(ret) |
| 51 | return json |
nothing calls this directly
no test coverage detected