anasmkh commited on
Commit
72f6a07
·
verified ·
1 Parent(s): 17c19e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -48
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
- 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()
 
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()