import joblib model = joblib.load("xgb.pkl") def predict(*args): input_data = [] for i in args: input_data.append(float(i)) input_data = np.asarray(input_data) # reshape the array as we are predicting for one instance input_data_reshaped = input_data.reshape(1, -1) prediction = model.predict(input_data_reshaped) if prediction[0] == 0: return "The Credit Score is Good" elif prediction[0] == 1: return "The Credit Score is Poor" else: return "The Credit Score is Standard" with gr.Blocks() as app: gr.Markdown( """ **Credit Score Classification**""" ) with gr.Row(): with gr.Column(): Annual_Income = gr.TextArea(label="Annual Income") Monthly_Inhand_Salary = gr.TextArea(label="Monthly Inhand Salary") Interest_Rate = gr.TextArea(label="Interest Rate") Num_of_Loan = gr.Slider( label="Number of Loans", minimum=1, maximum=10, step=1, randomize=True ) Delay_from_due_date = gr.Slider( label="Number of Delayed Days", minimum=-100, maximum=100, step=1, randomize=True, ) Num_of_Delayed_Payment = gr.Slider( label="Number of Delayed Payments", minimum=1, maximum=10, step=1, randomize=True, ) Credit_Mix = gr.Dropdown( label="Credit Mix (Bad: 0, Don't Have: 1, Good: 2, Standard: 3)", choices=[0,1,2,3], value=lambda: random.choice([0,1,2,3]), ) Outstanding_Debt = gr.TextArea(label="Outstanding Debt") Credit_Utilization_Ratio = gr.TextArea(label="Credit Utilization Ratio") Payment_of_Min_Amount = gr.Dropdown( label="Payment of Minimum Amount (NM: 0, No: 1, Yes: 2)", choices=[0,1,2], value=lambda: random.choice([0,1,2]), ) Total_EMI_per_month = gr.TextArea(label="Total Equated Monthly Installment") Amount_invested_monthly = gr.TextArea(label="Amount Invested Monthly") Monthly_Balance = gr.TextArea(label="Monthly Balance") Credit_History_Age_In_Years = gr.TextArea(label="Credit History in Years") StudentLoan = gr.Dropdown( label="Student Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) MortgageLoan= gr.Dropdown( label="Mortage Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) PersonalLoan = gr.Dropdown( label="Personal Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) DebtConsolidationLoan = gr.Dropdown( label="Debt Consolidation Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) Credit_BuilderLoan = gr.Dropdown( label="Credit Builder Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) HomeEquityLoan = gr.Dropdown( label="Home Equity Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) NotSpecified = gr.Dropdown( label="Unspecified Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) AutoLoan = gr.Dropdown( label="Auto Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) PaydayLoan = gr.Dropdown( label="Payday Loan (Don't Have: 0, Have: 1)", choices=[0,1], value=lambda: random.choice([0,1]), ) with gr.Column(): label = gr.Label() with gr.Row(): predict_btn = gr.Button(value="Predict") predict_btn.click( predict, inputs=[ Annual_Income, Monthly_Inhand_Salary, Interest_Rate, Num_of_Loan, Delay_from_due_date, Num_of_Delayed_Payment, Credit_Mix, Outstanding_Debt, Credit_Utilization_Ratio, Payment_of_Min_Amount, Total_EMI_per_month, Amount_invested_monthly, Monthly_Balance, Credit_History_Age_In_Years, StudentLoan, MortgageLoan, PersonalLoan, DebtConsolidationLoan, Credit_BuilderLoan, HomeEquityLoan, NotSpecified, AutoLoan, PaydayLoan, ], outputs=[label], ) app.launch()