File size: 859 Bytes
54eddc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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]}