Demo_ML101 / app.py
Kurkur99's picture
Update app.py
e43fc16 verified
raw
history blame
No virus
977 Bytes
import streamlit as st
import pandas as pd
import re
import tensorflow as tf
import tensorflow_hub as hub
import joblib
# Load model and label encoder
def load_model():
return tf.keras.models.load_model('path_to_my_model', custom_objects={'KerasLayer': hub.KerasLayer})
model = load_model()
label_encoder = joblib.load('label_encoder.joblib')
# Streamlit application title
st.title('Transaction Category Predictor')
# User input for transaction description
user_input = st.text_input("Enter a transaction description:")
# Process user input and display prediction
if user_input:
processed_input = re.sub(r'\d+', '', user_input)
input_df = pd.DataFrame([processed_input], columns=['transaction_desc'])
prediction = model.predict(input_df['transaction_desc'])
predicted_category_index = prediction.argmax()
predicted_category = label_encoder.inverse_transform([predicted_category_index])[0]
st.write(f"Predicted Category: {predicted_category}")