Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import tensorflow as tf | |
from sklearn.preprocessing import StandardScaler, LabelEncoder | |
# Load the model | |
model = tf.keras.models.load_model("banking_model.keras") | |
# Function to preprocess input data | |
def preprocess_input(input_data, label_encoders, scaler): | |
# Convert input data to DataFrame | |
input_df = pd.DataFrame([input_data]) | |
# Encode categorical variables | |
for col in label_encoders: | |
input_df[col] = label_encoders[col].transform(input_df[col]) | |
# Scale numerical variables | |
numerical_columns = input_df.select_dtypes(include=["int64", "float64"]).columns | |
input_df[numerical_columns] = scaler.transform(input_df[numerical_columns]) | |
return input_df | |
# Streamlit app | |
def main(): | |
st.title("Banking Stage Classification") | |
# Input fields | |
st.sidebar.header("User Input Features") | |
# Example feature inputs, adjust according to your actual features | |
credit_expiration = st.sidebar.number_input("Credit Expiration", min_value=0, value=0) | |
dpd = st.sidebar.number_input("DPD", min_value=0, value=0) | |
feature1 = st.sidebar.selectbox("Feature 1", options=["Yes", "No"]) | |
feature2 = st.sidebar.selectbox("Feature 2", options=["Yes", "No"]) | |
stage_last_month = st.sidebar.selectbox("Stage As Last Month", options=[1, 2, 3]) | |
# Prepare input data | |
input_data = { | |
'Credit Expiration': credit_expiration, | |
'DPD': dpd, | |
'Feature 1': feature1, | |
'Feature 2': feature2, | |
'Stage As Last Month': stage_last_month | |
} | |
# Preprocess the input | |
processed_input = preprocess_input(input_data, label_encoders, scaler) | |
# Make prediction | |
if st.sidebar.button("Predict"): | |
prediction = model.predict(processed_input) | |
predicted_stage = np.argmax(prediction, axis=1) + 1 # Adjust if necessary | |
st.success(f"Predicted Current Stage: {predicted_stage[0]}") | |
if __name__ == "__main__": | |
main() |