Youngestdeveloper commited on
Commit
e456033
·
verified ·
1 Parent(s): cff6e26
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+
4
+ # Load the trained model
5
+ model = joblib.load("loan_classifier.joblib")
6
+
7
+ # Load Standared Scaler
8
+ scalar = joblib.load("std_scaler.bin")
9
+
10
+
11
+ def predict_loan_status(
12
+ int_rate,
13
+ installment,
14
+ log_annual_inc,
15
+ dti,
16
+ fico,
17
+ revol_bal,
18
+ revol_util,
19
+ inq_last_6mths,
20
+ delinq_2yrs,
21
+ pub_rec,
22
+ installment_to_income_ratio,
23
+ credit_history,
24
+ ):
25
+ input_dict = {
26
+ "int.rate": int_rate,
27
+ "installment": installment,
28
+ "log.annual.inc": log_annual_inc,
29
+ "dti": dti,
30
+ "fico": fico,
31
+ "revol.bal": revol_bal,
32
+ "revol.util": revol_util,
33
+ "inq.last.6mths": inq_last_6mths,
34
+ "delinq.2yrs": delinq_2yrs,
35
+ "pub.rec": pub_rec,
36
+ "installment_to_income_ratio": installment_to_income_ratio,
37
+ "credit_history": credit_history,
38
+ }
39
+ # Convert the dictionary to a 2D array
40
+ input_array = [list(input_dict.values())]
41
+ scaled_array = scalar.transform(input_array)
42
+ prediction = model.predict(scaled_array)[0]
43
+
44
+ if prediction == 0:
45
+ return "Loan fully paid"
46
+ else:
47
+ return "Loan not fully paid"
48
+
49
+
50
+ inputs = [
51
+ gr.Slider(0.06, 0.23, step=0.01, label="Interest Rate"),
52
+ gr.Slider(100, 950, step=10, label="Installment"),
53
+ gr.Slider(7, 15, step=0.1, label="Log Annual Income"),
54
+ gr.Slider(0, 40, step=1, label="DTI Ratio"),
55
+ gr.Slider(600, 850, step=1, label="FICO Score"),
56
+ gr.Slider(0, 120000, step=1000, label="Revolving Balance"),
57
+ gr.Slider(0, 120, step=1, label="Revolving Utilization"),
58
+ gr.Slider(0, 10, step=1, label="Inquiries in Last 6 Months"),
59
+ gr.Slider(0, 20, step=1, label="Delinquencies in Last 2 Years"),
60
+ gr.Slider(0, 10, step=1, label="Public Records"),
61
+ gr.Slider(0, 5, step=0.1, label="Installment to Income Ratio"),
62
+ gr.Slider(0, 1, step=0.01, label="Credit History"),
63
+ ]
64
+ outputs = [gr.Label(num_top_classes=2)]
65
+
66
+ title = "Loan Approval Classifier"
67
+ description = (
68
+ "Enter the details of the loan applicant to check if the loan is approved or not."
69
+ )
70
+ gr.Interface(
71
+ fn=predict_loan_status,
72
+ inputs=inputs,
73
+ outputs=outputs,
74
+ title=title,
75
+ description=description,
76
+ ).launch()