-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
60 lines (48 loc) · 2.47 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pickle
import streamlit as st
import warnings
# Ignore warnings
warnings.filterwarnings("ignore")
# Load the model
load = open('rnd.pkl', 'rb')
model = pickle.load(load)
load.close()
# Prediction function
def predict(Industrial_Risk, Management_Risk, Financial_Flexibility, Credibility, Competitiveness, Operating_Risk):
try:
prediction = model.predict([[Industrial_Risk, Management_Risk, Financial_Flexibility, Credibility, Competitiveness, Operating_Risk]])
return prediction[0] # Use prediction[0] to get the actual prediction value
except Exception as e:
st.error(f"An error occurred: {str(e)}")
def main():
st.title('Bankruptcy Prevention Prediction 📉')
st.markdown('Welcome to the Bankruptcy Prevention Prediction. This is a Random Forest machine learning model to predict BANKRUPTCY or NOT.')
st.markdown('Use the form below to predict whether a company will go bankrupt or not.')
def add_bg_from_url():
st.markdown(
f"""
<style>
.stApp {{
background-image: url('https://images.pexels.com/photos/186461/pexels-photo-186461.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1');
background-attachment: fixed;
background-size: cover
}}
</style>
""",
unsafe_allow_html=True
)
add_bg_from_url()
Industrial_Risk = st.selectbox('Industrial Risk:', [0, 0.5, 1], key='Industrial_Risk')
Management_Risk = st.selectbox('Management Risk:', [0, 0.5, 1], key='Management_Risk')
Financial_Flexibility = st.selectbox('Financial Flexibility:', [0, 0.5, 1], key='Financial_Flexibility')
Credibility = st.selectbox('Credibility:', [0, 0.5, 1], key='Credibility')
Competitiveness = st.selectbox('Competitiveness:', [0, 0.5, 1], key='Competitiveness')
Operating_Risk = st.selectbox('Operating Risk:', [0, 0.5, 1], key='Operating_Risk')
if st.button('Predict'):
Result = predict(Industrial_Risk, Management_Risk, Financial_Flexibility, Credibility, Competitiveness, Operating_Risk)
if Result == 0:
st.markdown('<h1 style="color: red; font-size: 36px;">Prediction: Bankruptcy</h1>', unsafe_allow_html=True)
else:
st.markdown('<h1 style="color: green; font-size: 36px;">Prediction: Non-Bankruptcy</h1>', unsafe_allow_html=True)
if __name__ == '__main__':
main()