Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pickle | |
import numpy as np | |
import warnings | |
warnings.filterwarnings("ignore", category=UserWarning, message="If you are loading a serialized model") | |
# Load your saved model | |
with open('xgb_credit_score_model.pkl', 'rb') as file: | |
model = pickle.load(file) | |
# Define the prediction function | |
def predict_credit_score(interest_rate, num_credit_inquiries, delay_from_due_date, | |
num_credit_card, num_bank_accounts, outstanding_debt, | |
num_of_delayed_payment, num_of_loan): | |
# Arrange inputs into a format that the model expects | |
features = np.array([[interest_rate, num_credit_inquiries, delay_from_due_date, | |
num_credit_card, num_bank_accounts, outstanding_debt, | |
num_of_delayed_payment, num_of_loan]]) | |
prediction = model.predict(features) | |
return f"Predicted Credit Score Category: {int(prediction[0])}" | |
# Define the Gradio input interface with labeled inputs | |
inputs = [ | |
gr.Number(label="Interest Rate"), | |
gr.Number(label="Number of Credit Inquiries"), | |
gr.Number(label="Days Delayed from Due Date"), | |
gr.Number(label="Number of Credit Cards"), | |
gr.Number(label="Number of Bank Accounts"), | |
gr.Number(label="Outstanding Debt"), | |
gr.Number(label="Number of Delayed Payments"), | |
gr.Number(label="Number of Loans") | |
] | |
# Define a detailed description with the correct category explanation | |
description = """ | |
Enter your details to get a prediction of your credit score category. | |
**Credit Score Categories**: | |
- 2 = Good | |
- 1 = Standard | |
- 0 = Poor | |
""" | |
# Define the Gradio interface | |
gr.Interface(fn=predict_credit_score, inputs=inputs, outputs="text", | |
title="Credit Score Predictor", | |
description=description).launch() |