Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
216e078 e474ead 216e078 e474ead 216e078 e474ead 216e078 | 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 27 28 29 30 31 32 33 34 | import pickle
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
class FakeContentClassifier:
def __init__(self, model_path, tokenizer_path, max_features=10000, max_len=250):
# Load the Keras model
self.model = load_model(model_path)
self.weights = load_model(model_path).get_weights()
self.model.set_weights(self.weights)
self.tokenizer = Tokenizer(max_features)
self.max_len = max_len
# Load the saved tokenizer
with open(tokenizer_path, 'rb') as f:
self.tokenizer = pickle.load(f)
def predict(self, text):
# Tokenize the input text
tokenized_sentences = self.tokenizer.texts_to_sequences([text])
train_padding = pad_sequences(tokenized_sentences, self.max_len)
# Make a prediction with the model
prediction = self.model.predict(train_padding)
# Return the prediction as a string
if prediction > 0.5:
return "The sentence is classified as fake."
else:
return "The sentence is classified as real."
|