testspace / app.py
VoidZeroe's picture
Upload 3 files
4ec4226
Raw History Blame Contribute Delete
3.82 kB
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
import tempfile
import pickle
import xgboost as xgb
plt.style.use('ggplot')
with open('xgboost_model.pkl', 'rb') as file:
model = pickle.load(file)
def upload_file(files):
file_paths = [file.name for file in files]
df = pd.read_csv(file_paths[0])
dmatrix = df.iloc[:,:].values
predictions = model.predict_proba(dmatrix).T[1]
df["target"] = predictions
df.to_csv("creditScorePrediction.csv")
img = df.hist(figsize=(30, 30))
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_file:
# Save the plot to the temporary file
plt.savefig(temp_file.name)
imagepath = (temp_file.name)
# Close the plot to release memory
plt.close()
return ["creditScorePrediction.csv"], imagepath, {"Credit Score":1}
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
gr.Markdown("""# Credit Scoring App for Lenders and Banks
Welcome to the Credit Scoring App! This powerful tool is designed to help lenders and banks assess the creditworthiness of their clients. By uploading a CSV file containing specific financial and demographic data, you'll receive credit scores that aid in making informed lending decisions.
""")
label = gr.Label("Credit Score prediction demo", show_label = False)
image=gr.Image(label = "uploaded data distribution")
file_output = gr.File(show_label = False)
upload_button = gr.UploadButton("Click to Upload a CSV file", file_types=[".csv"], file_count="multiple")
gr.Markdown("""
## Uploading Your CSV File
To get started, you need to upload a CSV file with the following fields in the given order:
* **ID:** A unique identifier for each client.
* **LIMIT_BAL:** The amount of credit given in NT dollars, including individual and family/supplementary credit.
* **SEX:** Gender of the customer (1 = male, 2 = female).
* **EDUCATION:** Level of education (1 = graduate school, 2 = university, 3 = high school, 0, 4, 5, 6 = others).
* **MARRIAGE:** Marital status (0 = others, 1 = married, 2 = single, 3 = others).
* **AGE:** Age of the customer in years.
The following variables represent the repayment status over several months, using a scale:
* **PAY_0 to PAY_6:** (-2 = No consumption, -1 = paid in full, 0 = use of revolving credit - paid minimum only, 1 = payment delay for one month, 2 = payment delay for two months, ... 8 = payment delay for eight months, 9 = payment delay for nine months and above).
The following variables represent the amount of bill statement in NT dollars for previous months:
* **BILL_AMT1 to BILL_AMT6:** Bill statement amount in the corresponding months.
The following variables represent the amount of previous payment in NT dollars for previous months:
* **PAY_AMT1 to PAY_AMT6:** Previous payment amount in the corresponding months.
## Generating Credit Scores
Once your CSV file is uploaded, the data will be fed into our advanced credit scoring model. The model will analyze the information provided and calculate a credit score for each client. This credit score will be appended as a new column at the end of each entry in the CSV file.
## Downloading Results
After the credit scores have been generated, you can easily download the updated CSV file by clicking on the "Download File" button. The file will contain the original data with the credit scores, making it convenient for you to integrate the results into your lending processes.
We hope you find our Credit Scoring App valuable in assessing credit risk and making well-informed lending decisions. Should you have any questions or feedback, please don't hesitate to reach out to us. Happy lending!""")
upload_button.upload(upload_file, upload_button, [file_output, image, label])
demo.launch()