VoidZeroe/testspace
0
1import gradio as gr2import pandas as pd3import matplotlib.pyplot as plt4import tempfile5import pickle6import xgboost as xgb7plt.style.use('ggplot')8 9 10with open('xgboost_model.pkl', 'rb') as file:11 model = pickle.load(file)12 13 14def upload_file(files):15 file_paths = [file.name for file in files]16 df = pd.read_csv(file_paths[0])17 dmatrix = df.iloc[:,:].values18 predictions = model.predict_proba(dmatrix).T[1]19 df["target"] = predictions20 df.to_csv("creditScorePrediction.csv")21 img = df.hist(figsize=(30, 30))22 with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_file:23 # Save the plot to the temporary file24 plt.savefig(temp_file.name)25 imagepath = (temp_file.name)26 # Close the plot to release memory27 plt.close()28 return ["creditScorePrediction.csv"], imagepath, {"Credit Score":1}29 30with gr.Blocks(theme=gr.themes.Monochrome()) as demo:31 gr.Markdown("""# Credit Scoring App for Lenders and Banks32 33Welcome 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.34 """)35 label = gr.Label("Credit Score prediction demo", show_label = False)36 image=gr.Image(label = "uploaded data distribution")37 file_output = gr.File(show_label = False)38 upload_button = gr.UploadButton("Click to Upload a CSV file", file_types=[".csv"], file_count="multiple")39 gr.Markdown("""40## Uploading Your CSV File41 42To get started, you need to upload a CSV file with the following fields in the given order:43 44* **ID:** A unique identifier for each client.45* **LIMIT_BAL:** The amount of credit given in NT dollars, including individual and family/supplementary credit.46* **SEX:** Gender of the customer (1 = male, 2 = female).47* **EDUCATION:** Level of education (1 = graduate school, 2 = university, 3 = high school, 0, 4, 5, 6 = others).48* **MARRIAGE:** Marital status (0 = others, 1 = married, 2 = single, 3 = others).49* **AGE:** Age of the customer in years.50 51The following variables represent the repayment status over several months, using a scale:52 53* **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).54 55The following variables represent the amount of bill statement in NT dollars for previous months:56 57* **BILL_AMT1 to BILL_AMT6:** Bill statement amount in the corresponding months.58 59The following variables represent the amount of previous payment in NT dollars for previous months:60 61* **PAY_AMT1 to PAY_AMT6:** Previous payment amount in the corresponding months.62 63## Generating Credit Scores64 65Once 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.66 67## Downloading Results68 69After 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.70 71We 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!""")72 73 74 upload_button.upload(upload_file, upload_button, [file_output, image, label])75 76demo.launch()77 