from joblib import load import numpy as np import gradio as gr # Load the model and transformers encoder = load("encoder.joblib") feature_scaler = load("Feature_scaler.joblib") model = load("Approval_Credit_prediction_model.joblib") def credit_classification(gender, car, properties, children, annual_income, education_level, marital_status, housing, age, work, mobile_phone, work_phone, phone, email, job, long_month, status): gender = encoder['CODE_GENDER'].transform([gender])[0] car = encoder["FLAG_OWN_CAR"].transform([car])[0] properties = encoder['FLAG_OWN_REALTY'].transform([properties])[0] children = encoder["CNT_CHILDREN"].transform([children])[0] education_level = encoder["NAME_EDUCATION_TYPE"].transform([education_level])[0] marital_status = encoder["NAME_FAMILY_STATUS"].transform([marital_status])[0] housing = encoder["NAME_HOUSING_TYPE"].transform([housing])[0] job = encoder["JOB"].transform([job])[0] status = encoder["STATUS"].transform([status])[0] feature = np.array([[gender, car, properties, children, annual_income, education_level, marital_status, housing, age, work, mobile_phone, work_phone, phone, email, job, long_month * -1, status]]) feature = feature_scaler.transform(feature) predict = model.predict(feature) predict = predict[0] if predict == 0: return gr.HTML(f"
You are Not Risk, your credit card will get approval
") else: return gr.HTML(f"
You are Risk, your credit card may be declined
") # Define input components inputs = [ gr.Dropdown(["F", "M"], label="Gender"), gr.Dropdown(["N", "Y"], label="Do you have cars?"), gr.Dropdown(["N", "Y"], label="Do you have property?"), gr.Dropdown(['2+ children', 'No children', '1 children'], label="How many children do you have?"), gr.Number(label="Annual Income($)"), gr.Dropdown(['Secondary / secondary special', 'Higher education', 'Incomplete higher', 'Lower secondary', 'Academic degree'], label="Your last education"), gr.Dropdown(['Married', 'Single / not married', 'Civil marriage', 'Separated', 'Widow'], label="Your marital status"), gr.Dropdown(['With parents', 'House / apartment', 'Rented apartment', 'Municipal apartment', 'Co-op apartment', 'Office apartment'], label="Your housing type"), gr.Number(label="Age"), gr.Number(label="Years of work"), gr.Dropdown([0, 1], label="Do you have mobile phone? (0 for 'no' 1 for 'yes')"), gr.Dropdown([0, 1], label="Do you have work phone? (0 for 'no' 1 for 'yes')"), gr.Dropdown([0, 1], label="Do you have phone? (0 for 'no' 1 for 'yes')"), gr.Dropdown([0, 1], label="Do you have email? (0 for 'no' 1 for 'yes')"), gr.Dropdown(['Managers', 'Private service staff', 'Laborers', 'Core staff', 'Drivers', 'High skill tech staff', 'Realty agents', 'Secretaries', 'Accountants', 'Sales staff', 'Medicine staff', 'Waiters/barmen staff', 'Low-skill Laborers', 'Cleaning staff', 'HR staff', 'Cooking staff', 'Security staff', 'IT staff'], label="Your job (if you can't find your job on the list, choose similar job)"), gr.Number(label="How long you have been using credit card?"), gr.Dropdown(['paid off that month', '1-29 days past due', 'No loan for the month', '60-89 days overdue', '30-59 days past due', 'Overdue or bad debts, write-offs for more than 150 days', '90-119 days overdue', '120-149 days overdue'], label="Punctuality of payment") ] # Create Gradio interface UI = gr.Interface(fn=credit_classification, inputs=inputs, outputs=gr.HTML(label="Approval Credit Card Status"), title="Credit Card Approval Prediction") UI.launch()