File size: 1,923 Bytes
b0f3a2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
import streamlit as st
import numpy as np
import pandas as pd
import tensorflow as tf
import joblib
from sklearn.preprocessing import LabelEncoder, StandardScaler

try:
    model = tf.keras.models.load_model("banking_model.keras")  
    scaler = joblib.load("scaler.pkl")
    label_encoders = joblib.load("label_encoders.pkl")
except Exception as e:
    st.error(f"Error loading model or preprocessors: {e}")
    st.stop()


st.title("πŸ“Š Banking App")
st.write("Enter the feature values below to predict the classification stage.")

if not label_encoders:
    st.error("Label encoders are empty. Make sure the model was trained correctly.")
    st.stop()

numerical_inputs = {}
categorical_inputs = {}

try:
    numerical_features = list(scaler.feature_names_in_) 
    categorical_features = list(label_encoders.keys())
except AttributeError:
    st.error("Scaler or encoders are not properly loaded.")
    st.stop()

for feature in numerical_features:
    numerical_inputs[feature] = st.number_input(f"Enter {feature}", value=0.0)

for feature in categorical_features:
    if label_encoders[feature].classes_.size > 0:  
        categorical_inputs[feature] = st.selectbox(f"Select {feature}", label_encoders[feature].classes_)
    else:
        st.error(f"Label encoder for {feature} is empty.")
        st.stop()


if st.button("Predict"):
    try:
        for feature in categorical_inputs:
            categorical_inputs[feature] = label_encoders[feature].transform([categorical_inputs[feature]])[0]

        input_data = pd.DataFrame([{**numerical_inputs, **categorical_inputs}])

        input_data[numerical_features] = scaler.transform(input_data[numerical_features])

        prediction = model.predict(input_data)
        predicted_class = np.argmax(prediction)

        st.success(f"βœ… Predicted Classification Stage: {predicted_class}")

    except Exception as e:
        st.error(f"Prediction error: {e}")