Spaces:
Running
Running
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import tensorflow as tf | |
import joblib | |
# Load trained model | |
model = tf.keras.models.load_model("banking_model.keras") | |
# Load encoders and scaler | |
label_encoders = joblib.load("label_encoders.pkl") | |
scaler = joblib.load("scaler.pkl") | |
# Define feature names | |
numerical_features = ["DPD", "Credit Expiration"] | |
binary_features = ["Feature1", "Feature2", "Feature3"] # Replace with actual binary features | |
stage_feature = "Stage As Last Month" | |
st.title("Classification Prediction App") | |
# Create input fields for user input | |
user_input = {} | |
# Numerical inputs (DPD, Credit Expiration) | |
for feature in numerical_features: | |
user_input[feature] = st.number_input(f"Enter {feature}", value=0, min_value=0) | |
# Binary features (Yes/No) | |
for feature in binary_features: | |
user_input[feature] = st.selectbox(f"{feature} (Yes/No)", ["Yes", "No"]) | |
user_input[feature] = 1 if user_input[feature] == "Yes" else 0 # Convert to 1/0 | |
# Stage as Last Month (Dropdown 1, 2, 3) | |
user_input[stage_feature] = st.selectbox("Stage As Last Month", [1, 2, 3]) | |
# Convert input to DataFrame | |
input_df = pd.DataFrame([user_input]) | |
# Apply scaling | |
input_df[numerical_features] = scaler.transform(input_df[numerical_features]) | |
# Predict when user clicks button | |
if st.button("Predict"): | |
prediction = model.predict(input_df) | |
predicted_stage = np.argmax(prediction) | |
st.success(f"Predicted Stage: {predicted_stage}") | |
if __name__ == "__main__": | |
main() |