Spaces:
Runtime error
Runtime error
File size: 1,348 Bytes
6ac585c d703d99 6ac585c d703d99 6ac585c d703d99 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import os, pickle
import logging
from flask import Flask, jsonify, render_template, request
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route('/api/predict', methods=['POST'])
def predict():
try:
# load and parse input
data = request.json
vector = [
float(data['age']),
data['travel'],
data['department'],
float(data['distance']),
float(data['education']),
data['gender'],
float(data['satisfaction']),
data['maritalstatus'],
float(data['income']),
data['overtime'],
float(data['totalyears']),
float(data['years']),
float(data['lastpromotion'])
]
# app.logging.info(f'vector: {vector}')
# print(f'vector: {vector}\n')
# load the model
with open(os.path.join('data', 'logistic.pkcls'), 'rb') as file:
model = pickle.load(file)
predictions = model(vector, 1)
# app.logging.info(f'predictions: {predictions}')
# print(f'predictions: {predictions}\n')
# send the response
return jsonify({ "predictions": { "leave": predictions[0], "stay": predictions[1] } })
except Exception as e:
return jsonify({"error": repr(e)})
if __name__ == "__main__":
app.logger.setLevel(logging.INFO)
app.run(host="0.0.0.0", port=7860)
|