# utils.py (Helper Functions) import pickle import numpy as np def load_model(): """ Loads the trained model from file. """ with open("models/model.pkl", "rb") as file: model = pickle.load(file) # Use pickle to load the model return model def model_predict(email): """ Predicts using the loaded model. """ model = load_model() # Load the model before predicting prediction = model.predict([email]) # Use the predict method to make predictions # If the email is spam, prediction should be 1, otherwise 0 # Convert the prediction to 1 or -1 as specified prediction = 1 if prediction[0] == 1 else -1 return prediction with open("models/model.pkl", "rb") as file: model = pickle.load(file) print("Model loaded successfully!")