anasmkh commited on
Commit
b0f3a2d
·
verified ·
1 Parent(s): f418190

add app file

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import tensorflow as tf
5
+ import joblib
6
+ from sklearn.preprocessing import LabelEncoder, StandardScaler
7
+
8
+ try:
9
+ model = tf.keras.models.load_model("banking_model.keras")
10
+ scaler = joblib.load("scaler.pkl")
11
+ label_encoders = joblib.load("label_encoders.pkl")
12
+ except Exception as e:
13
+ st.error(f"Error loading model or preprocessors: {e}")
14
+ st.stop()
15
+
16
+
17
+ st.title("📊 Banking App")
18
+ st.write("Enter the feature values below to predict the classification stage.")
19
+
20
+ if not label_encoders:
21
+ st.error("Label encoders are empty. Make sure the model was trained correctly.")
22
+ st.stop()
23
+
24
+ numerical_inputs = {}
25
+ categorical_inputs = {}
26
+
27
+ try:
28
+ numerical_features = list(scaler.feature_names_in_)
29
+ categorical_features = list(label_encoders.keys())
30
+ except AttributeError:
31
+ st.error("Scaler or encoders are not properly loaded.")
32
+ st.stop()
33
+
34
+ for feature in numerical_features:
35
+ numerical_inputs[feature] = st.number_input(f"Enter {feature}", value=0.0)
36
+
37
+ for feature in categorical_features:
38
+ if label_encoders[feature].classes_.size > 0:
39
+ categorical_inputs[feature] = st.selectbox(f"Select {feature}", label_encoders[feature].classes_)
40
+ else:
41
+ st.error(f"Label encoder for {feature} is empty.")
42
+ st.stop()
43
+
44
+
45
+ if st.button("Predict"):
46
+ try:
47
+ for feature in categorical_inputs:
48
+ categorical_inputs[feature] = label_encoders[feature].transform([categorical_inputs[feature]])[0]
49
+
50
+ input_data = pd.DataFrame([{**numerical_inputs, **categorical_inputs}])
51
+
52
+ input_data[numerical_features] = scaler.transform(input_data[numerical_features])
53
+
54
+ prediction = model.predict(input_data)
55
+ predicted_class = np.argmax(prediction)
56
+
57
+ st.success(f"✅ Predicted Classification Stage: {predicted_class}")
58
+
59
+ except Exception as e:
60
+ st.error(f"Prediction error: {e}")