Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,57 +2,46 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import tensorflow as tf
|
5 |
-
|
6 |
|
7 |
-
# Load
|
8 |
model = tf.keras.models.load_model("banking_model.keras")
|
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 |
-
'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()
|
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import tensorflow as tf
|
5 |
+
import joblib
|
6 |
|
7 |
+
# Load trained model
|
8 |
model = tf.keras.models.load_model("banking_model.keras")
|
9 |
|
10 |
+
# Load encoders and scaler
|
11 |
+
label_encoders = joblib.load("label_encoders.pkl")
|
12 |
+
scaler = joblib.load("scaler.pkl")
|
13 |
+
|
14 |
+
# Define the input features
|
15 |
+
feature_names = [
|
16 |
+
# Add all the feature column names used in training
|
17 |
+
]
|
18 |
+
|
19 |
+
st.title("Classification Prediction App")
|
20 |
+
|
21 |
+
# Create input fields for user input
|
22 |
+
user_input = {}
|
23 |
+
for feature in feature_names:
|
24 |
+
if feature in label_encoders: # If it's a categorical feature
|
25 |
+
options = list(label_encoders[feature].classes_)
|
26 |
+
user_input[feature] = st.selectbox(f"Select {feature}", options)
|
27 |
+
else: # If it's a numerical feature
|
28 |
+
user_input[feature] = st.number_input(f"Enter {feature}", value=0.0)
|
29 |
+
|
30 |
+
# Convert input to DataFrame
|
31 |
+
input_df = pd.DataFrame([user_input])
|
32 |
+
|
33 |
+
# Apply encoding & scaling
|
34 |
+
for col, encoder in label_encoders.items():
|
35 |
+
input_df[col] = encoder.transform(input_df[col])
|
36 |
+
|
37 |
+
input_df[feature_names] = scaler.transform(input_df[feature_names])
|
38 |
+
|
39 |
+
# Predict when user clicks button
|
40 |
+
if st.button("Predict"):
|
41 |
+
prediction = model.predict(input_df)
|
42 |
+
predicted_stage = np.argmax(prediction)
|
43 |
+
st.success(f"Predicted Stage: {predicted_stage}")
|
44 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
main()
|