Update app.py
Browse files
app.py
CHANGED
|
@@ -1,83 +1,39 @@
|
|
| 1 |
-
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 4 |
-
from
|
| 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 |
-
# Flask routes
|
| 42 |
-
@app.route("/")
|
| 43 |
-
def home():
|
| 44 |
-
return render_template("index.html")
|
| 45 |
-
|
| 46 |
-
@app.route('/predict', methods=['POST'])
|
| 47 |
-
def predict():
|
| 48 |
-
try:
|
| 49 |
-
# Extract input values from the form
|
| 50 |
-
outstanding_debt = float(request.form['outstanding_debt'])
|
| 51 |
-
credit_mix = int(request.form['credit_mix'])
|
| 52 |
-
credit_history_age = float(request.form['credit_history_age'])
|
| 53 |
-
monthly_balance = float(request.form['monthly_balance'])
|
| 54 |
-
payment_behaviour = float(request.form['payment_behaviour'])
|
| 55 |
-
annual_income = float(request.form['annual_income'])
|
| 56 |
-
delayed_payments = int(request.form['delayed_payments'])
|
| 57 |
-
|
| 58 |
-
# Prepare input data for prediction
|
| 59 |
-
input_data = [[
|
| 60 |
-
outstanding_debt, credit_mix, credit_history_age,
|
| 61 |
-
monthly_balance, payment_behaviour, annual_income,
|
| 62 |
-
delayed_payments
|
| 63 |
-
]]
|
| 64 |
-
|
| 65 |
-
# Predict using the loaded model
|
| 66 |
-
prediction = loaded_model.predict(input_data)[0] # Use loaded_model here
|
| 67 |
-
|
| 68 |
-
# Map the prediction to the category name
|
| 69 |
-
target_names = {0: "Good", 1: "Poor", 2: "Standard"}
|
| 70 |
-
prediction_text = target_names.get(prediction, "Unknown")
|
| 71 |
-
|
| 72 |
-
# Render result.html with the prediction
|
| 73 |
-
return render_template('result.html', prediction=prediction_text)
|
| 74 |
-
except Exception as e:
|
| 75 |
-
return f"An error occurred: {str(e)}"
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
#if __name__ == "__main__":
|
| 79 |
-
#app.run(debug=True)
|
| 80 |
-
|
| 81 |
-
if __name__ == "__main__":
|
| 82 |
-
app.run(host="0.0.0.0", port=8080)
|
| 83 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from joblib import load
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
model = load("credit_classifier.joblib")
|
| 8 |
+
|
| 9 |
+
# Prediction function
|
| 10 |
+
def predict_credit_score(outstanding_debt, credit_mix, credit_history_age, monthly_balance,
|
| 11 |
+
payment_behaviour, annual_income, delayed_payments):
|
| 12 |
+
input_data = [[
|
| 13 |
+
outstanding_debt, credit_mix, credit_history_age,
|
| 14 |
+
monthly_balance, payment_behaviour, annual_income,
|
| 15 |
+
delayed_payments
|
| 16 |
+
]]
|
| 17 |
+
prediction = model.predict(input_data)[0]
|
| 18 |
+
|
| 19 |
+
target_names = {0: "Good", 1: "Poor", 2: "Standard"}
|
| 20 |
+
return target_names.get(prediction, "Unknown")
|
| 21 |
+
|
| 22 |
+
# Gradio interface
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=predict_credit_score,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Number(label="Outstanding Debt"),
|
| 27 |
+
gr.Number(label="Credit Mix"),
|
| 28 |
+
gr.Number(label="Credit History Age"),
|
| 29 |
+
gr.Number(label="Monthly Balance"),
|
| 30 |
+
gr.Number(label="Payment Behaviour"),
|
| 31 |
+
gr.Number(label="Annual Income"),
|
| 32 |
+
gr.Number(label="Delayed Payments"),
|
| 33 |
+
],
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Credit Scoring Classifier",
|
| 36 |
+
description="Enter your credit-related information to classify your credit score as Good, Standard, or Poor.",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|