#importing necessary packages and modules import gradio as gr import joblib import numpy as np # Load the trained loan model model = joblib.load("loan_RFmodel.joblib") #This function #Takes input from user and uses the trained model to predict loan eligibility. def predict_loan_status( married, dependents, education, applicant_income, coapplicant_income, loan_amount, loan_amount_term, credit_history, property_area ): #Encoding the categorical variables for model prediction married = 1 if married == "Yes" else 0 education = 1 if education == "Graduate" else 0 property_area_map = { "Urban": 2, "Semiurban": 1, "Rural": 0 } property_area = property_area_map[property_area] # Combine inputs into model-ready format features = np.array([[ married, dependents, education, applicant_income, coapplicant_income, loan_amount, loan_amount_term, credit_history, property_area ]]) # Making prediction prediction = model.predict(features)[0] return "Loan Approved" if prediction == 1 else "Loan Rejected" # Building the Gradio User Interface Gardio_interface = gr.Interface( fn=predict_loan_status, inputs=[ gr.Radio(["Yes", "No"], label="Married"), gr.Number(label="Number of Dependents"), gr.Radio(["Graduate", "Not Graduate"], label="Education"), gr.Number(label="Applicant Income"), gr.Number(label="Coapplicant Income"), gr.Number(label="Loan Amount"), gr.Number(label="Loan Amount Term(Days)"), gr.Radio([1, 0], label="Credit History (1 = Good, 0 = Bad)"), gr.Radio(["Urban", "Semiurban", "Rural"], label="Property Area"), ], outputs="text", title="Loan Status Prediction System", description="Predict whether a loan application will be approved or rejected using a trained machine learning model." ) if __name__ == "__main__": Gardio_interface.launch()