Spaces:
Sleeping
Sleeping
| from flask import Flask, request, render_template | |
| from flask_cors import CORS | |
| import numpy as np | |
| import pandas as pd | |
| import pickle | |
| app = Flask(__name__) | |
| CORS(app) | |
| def index(): | |
| return render_template('index.html') | |
| def report(): | |
| return render_template('report.html') | |
| def code(): | |
| return render_template('code.html') | |
| def analysis2(missedprior,totalmissed,reminded,age,hyper,diabetes): | |
| column = ['missed_appointment_before', 'sum_missed', 'Age', 'SMS_received', | |
| 'Hypertension', 'Diabetes'] | |
| serInput = [missedprior,totalmissed,age,reminded,hyper,diabetes] | |
| data = pd.DataFrame([serInput], columns=column) | |
| filename = './models/xgbnoshow.sav' | |
| model = pickle.load(open(filename, 'rb')) | |
| data = np.ascontiguousarray(data, dtype=np.float32) | |
| r = model.predict(data) | |
| for i in r: | |
| if r == 0: | |
| result = str("Might Miss") | |
| else: | |
| result = str("Might Show") | |
| proba = np.max(model.predict_proba(data)*100, axis=1) | |
| pred = str( (result) + ' With A Probability of: ' +'%.2f' % (proba) +'%') | |
| return pred | |
| def uploadsnoshow(): | |
| if request.method == 'GET': | |
| # Get the file from post request | |
| missedprior = int(request.args['MissedPrior']) | |
| totalmissed = int(request.args['TotalMissed']) | |
| reminded = int(request.args['Reminded']) | |
| age = int(request.args['Age']) | |
| hyper = int(request.args['Hypertension']) | |
| diabetes = int(request.args['Diabetes']) | |
| serInput = [missedprior,totalmissed,reminded,age,hyper,diabetes] | |
| result = analysis2(missedprior,totalmissed,reminded,age,hyper,diabetes) | |
| return render_template('index.html', predictions=result) | |
| return None | |
| if __name__ == "__main__": | |
| print("๐ Starting Flask app...") | |
| app.run(debug=True, host="0.0.0.0", port=7860) | |