-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (32 loc) · 1.17 KB
/
app.py
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
from flask import Flask, request, jsonify, render_template
import pickle
import numpy as np
import pandas as pd
import sys
from utils.preprocess import preprocess_user_input
app = Flask(__name__)
# Load the model objects
with open('models/model.pkl', 'rb') as f:
model = pickle.load(f)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
# Get form data
user_input = request.form.to_dict()
# Convert form data to DataFrame
data = pd.DataFrame([user_input])
# Preprocess user input
processed_input = preprocess_user_input(data)
## Make prediction using the preprocessed input
# Make a prediction
prediction = model.predict(processed_input.values).tolist()
# Get the model accuracy
#accuracy = accuracy_rf * 100 # assuming accuracy_rf is the model's accuracy
accuracy = 81.48
# Display the result
return render_template('index.html', prediction_text=f'Churn Prediction: {"Yes" if prediction[0] == 1 else "No"}',
accuracy_text=f'Model Accuracy: {accuracy:.2f}%')
if __name__ == '__main__':
app.run(debug=True)