nunclud commited on
Commit
6551468
·
verified ·
1 Parent(s): 802ee17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import joblib
3
  import numpy as np
@@ -5,6 +6,9 @@ import numpy as np
5
  # Load the trained loan model
6
  model = joblib.load("loan_RFmodel.joblib")
7
 
 
 
 
8
  def predict_loan_status(
9
  married,
10
  dependents,
@@ -16,14 +20,8 @@ def predict_loan_status(
16
  credit_history,
17
  property_area
18
  ):
19
- """
20
- This function:
21
- - Receives user inputs
22
- - Converts categorical inputs to numeric values
23
- - Uses the trained model to predict loan status
24
- """
25
 
26
- # Encoding categorical variables (must match training logic)
27
  married = 1 if married == "Yes" else 0
28
  education = 1 if education == "Graduate" else 0
29
 
@@ -47,13 +45,13 @@ def predict_loan_status(
47
  property_area
48
  ]])
49
 
50
- # Make prediction
51
  prediction = model.predict(features)[0]
52
 
53
  return "Loan Approved" if prediction == 1 else "Loan Rejected"
54
 
55
- # Gradio Interface
56
- interface = gr.Interface(
57
  fn=predict_loan_status,
58
  inputs=[
59
  gr.Radio(["Yes", "No"], label="Married"),
@@ -72,4 +70,4 @@ interface = gr.Interface(
72
  )
73
 
74
  if __name__ == "__main__":
75
- interface.launch()
 
1
+ #importing necessary packages and modules
2
  import gradio as gr
3
  import joblib
4
  import numpy as np
 
6
  # Load the trained loan model
7
  model = joblib.load("loan_RFmodel.joblib")
8
 
9
+ #This function
10
+ #Takes input from user and uses the trained model to predict loan eligibility.
11
+
12
  def predict_loan_status(
13
  married,
14
  dependents,
 
20
  credit_history,
21
  property_area
22
  ):
 
 
 
 
 
 
23
 
24
+ #Encoding the categorical variables for model prediction
25
  married = 1 if married == "Yes" else 0
26
  education = 1 if education == "Graduate" else 0
27
 
 
45
  property_area
46
  ]])
47
 
48
+ # Making prediction
49
  prediction = model.predict(features)[0]
50
 
51
  return "Loan Approved" if prediction == 1 else "Loan Rejected"
52
 
53
+ # Building the Gradio User Interface
54
+ Gardio_interface = gr.Interface(
55
  fn=predict_loan_status,
56
  inputs=[
57
  gr.Radio(["Yes", "No"], label="Married"),
 
70
  )
71
 
72
  if __name__ == "__main__":
73
+ Gardio_interface.launch()