CoolFace
Apppublic

swapnapapireddy3/Credict-Risk-Modelling-using-classification

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
main.py67 linesDownload Raw Back to root
1import streamlit as st
2from prediction_helper import predict  # Ensure this is correctly linked to your prediction_helper.py
3
4# Set the page configuration and title
5st.set_page_config(page_title="Lauki Finance: Credit Risk Modelling", page_icon="๐Ÿ“Š")
6st.title("Lauki Finance: Credit Risk Modelling")
7
8# Create rows of three columns each
9row1 = st.columns(3)
10row2 = st.columns(3)
11row3 = st.columns(3)
12row4 = st.columns(3)
13
14# Assign inputs to the first row with default values
15with row1[0]:
16    age = st.number_input('Age', min_value=18, step=1, max_value=100, value=28)
17with row1[1]:
18    income = st.number_input('Income', min_value=0, value=1200000)
19with row1[2]:
20    loan_amount = st.number_input('Loan Amount', min_value=0, value=2560000)
21
22# Calculate Loan to Income Ratio and display it
23loan_to_income_ratio = loan_amount / income if income > 0 else 0
24with row2[0]:
25    st.text("Loan to Income Ratio:")
26    st.text(f"{loan_to_income_ratio:.2f}")  # Display as a text field
27
28# Assign inputs to the remaining controls
29with row2[1]:
30    loan_tenure_months = st.number_input('Loan Tenure (months)', min_value=0, step=1, value=36)
31with row2[2]:
32    avg_dpd_per_delinquency = st.number_input('Avg DPD', min_value=0, value=20)
33
34with row3[0]:
35    delinquency_ratio = st.number_input('Delinquency Ratio', min_value=0, max_value=100, step=1, value=30)
36with row3[1]:
37    credit_utilization_ratio = st.number_input('Credit Utilization Ratio', min_value=0, max_value=100, step=1, value=30)
38with row3[2]:
39    num_open_accounts = st.number_input('Open Loan Accounts', min_value=1, max_value=4, step=1, value=2)
40
41
42with row4[0]:
43    residence_type = st.selectbox('Residence Type', ['Owned', 'Rented', 'Mortgage'])
44with row4[1]:
45    loan_purpose = st.selectbox('Loan Purpose', ['Education', 'Home', 'Auto', 'Personal'])
46with row4[2]:
47    loan_type = st.selectbox('Loan Type', ['Unsecured', 'Secured'])
48
49
50# Button to calculate risk
51if st.button('Calculate Risk'):
52    # Call the predict function from the helper module
53    # print((age, income, loan_amount, loan_tenure_months, avg_dpd_per_delinquency,
54    #                                             delinquency_ratio, credit_utilization_ratio, num_open_accounts,
55    #                                             residence_type, loan_purpose, loan_type))
56    probability, credit_score, rating = predict(age, income, loan_amount, loan_tenure_months, avg_dpd_per_delinquency,
57                                                delinquency_ratio, credit_utilization_ratio, num_open_accounts,
58                                                residence_type, loan_purpose, loan_type)
59
60    # Display the results
61    st.write(f"Deafult Probability: {probability:.2%}")
62    st.write(f"Credit Score: {credit_score}")
63    st.write(f"Rating: {rating}")
64
65# Footer
66# st.markdown('_Project From Codebasics ML Course_')
67