Spaces:
Sleeping
Sleeping
update interface
Browse files
app.py
CHANGED
@@ -1,73 +1,58 @@
|
|
1 |
import streamlit as st
|
2 |
-
import numpy as np
|
3 |
import pandas as pd
|
|
|
4 |
import tensorflow as tf
|
5 |
-
import
|
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 |
-
st.
|
36 |
-
st.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
if
|
53 |
-
|
54 |
-
|
55 |
-
st.
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
try:
|
60 |
-
for feature in categorical_inputs:
|
61 |
-
categorical_inputs[feature] = label_encoders[feature].transform([categorical_inputs[feature]])[0]
|
62 |
-
|
63 |
-
input_data = pd.DataFrame([{**numerical_inputs, **categorical_inputs}])
|
64 |
-
|
65 |
-
input_data[numerical_features] = scaler.transform(input_data[numerical_features])
|
66 |
-
|
67 |
-
prediction = model.predict(input_data)
|
68 |
-
predicted_class = np.argmax(prediction)
|
69 |
-
|
70 |
-
st.success(f"β
Predicted Classification Stage: {predicted_class}")
|
71 |
-
|
72 |
-
except Exception as e:
|
73 |
-
st.error(f"Prediction error: {e}")
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
import tensorflow as tf
|
5 |
+
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
6 |
+
|
7 |
+
# Load the model
|
8 |
+
model = tf.keras.models.load_model("banking_model.keras")
|
9 |
+
|
10 |
+
# Function to preprocess input data
|
11 |
+
def preprocess_input(input_data, label_encoders, scaler):
|
12 |
+
# Convert input data to DataFrame
|
13 |
+
input_df = pd.DataFrame([input_data])
|
14 |
+
|
15 |
+
# Encode categorical variables
|
16 |
+
for col in label_encoders:
|
17 |
+
input_df[col] = label_encoders[col].transform(input_df[col])
|
18 |
+
|
19 |
+
# Scale numerical variables
|
20 |
+
numerical_columns = input_df.select_dtypes(include=["int64", "float64"]).columns
|
21 |
+
input_df[numerical_columns] = scaler.transform(input_df[numerical_columns])
|
22 |
+
|
23 |
+
return input_df
|
24 |
+
|
25 |
+
# Streamlit app
|
26 |
+
def main():
|
27 |
+
st.title("Banking Stage Classification")
|
28 |
+
|
29 |
+
# Input fields
|
30 |
+
st.sidebar.header("User Input Features")
|
31 |
+
|
32 |
+
# Example feature inputs, adjust according to your actual features
|
33 |
+
credit_expiration = st.sidebar.number_input("Credit Expiration", min_value=0, value=0)
|
34 |
+
dpd = st.sidebar.number_input("DPD", min_value=0, value=0)
|
35 |
+
feature1 = st.sidebar.selectbox("Feature 1", options=["Yes", "No"])
|
36 |
+
feature2 = st.sidebar.selectbox("Feature 2", options=["Yes", "No"])
|
37 |
+
stage_last_month = st.sidebar.selectbox("Stage As Last Month", options=[1, 2, 3])
|
38 |
+
|
39 |
+
# Prepare input data
|
40 |
+
input_data = {
|
41 |
+
'Credit Expiration': credit_expiration,
|
42 |
+
'DPD': dpd,
|
43 |
+
'Feature 1': feature1,
|
44 |
+
'Feature 2': feature2,
|
45 |
+
'Stage As Last Month': stage_last_month
|
46 |
+
}
|
47 |
+
|
48 |
+
# Preprocess the input
|
49 |
+
processed_input = preprocess_input(input_data, label_encoders, scaler)
|
50 |
+
|
51 |
+
# Make prediction
|
52 |
+
if st.sidebar.button("Predict"):
|
53 |
+
prediction = model.predict(processed_input)
|
54 |
+
predicted_stage = np.argmax(prediction, axis=1) + 1 # Adjust if necessary
|
55 |
+
st.success(f"Predicted Current Stage: {predicted_stage[0]}")
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|