from tensorflow.keras.models import load_model import joblib from tensorflow.keras.preprocessing.sequence import pad_sequences import numpy as np import re # Load the model, tokenizer, and label encoder model = load_model("transactify.h5") tokenizer = joblib.load("tokenizer.joblib") label_encoder = joblib.load("label_encoder.joblib") def clean_text(text): text = text.lower() text = re.sub(r"\d+", "", text) text = re.sub(r"[^\w\s]", "", text) return text.strip() def predict(text): cleaned_text = clean_text(text) sequence = tokenizer.texts_to_sequences([cleaned_text]) padded_sequence = pad_sequences(sequence, maxlen=100) prediction = model.predict(padded_sequence) predicted_label = np.argmax(prediction, axis=1) category = label_encoder.inverse_transform(predicted_label) return {"category": category[0]}