-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (24 loc) · 822 Bytes
/
app.py
File metadata and controls
31 lines (24 loc) · 822 Bytes
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
from flask import Flask, request, jsonify, send_from_directory
import joblib
import numpy as np
from flask_cors import CORS
import os
app = Flask(__name__)
CORS(app)
model = joblib.load("model.pkl")
@app.route('/')
def home():
return send_from_directory('.', 'index.html')
@app.route('/predict', methods=['POST'])
def predict():
data = request.json
features = np.array([[data['age'], data['income'], data['debt'], data['openLoans'], data['latePayments']]])
risk = model.predict_proba(features)[0][1] * 100
return jsonify({'risk_percent': risk})
@app.route('/health')
def health():
return jsonify({'status': 'healthy', 'service': 'credit-risk-scoring'})
if __name__ == "__main__":
import os
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port, debug=False)