Spaces:
Sleeping
Sleeping
File size: 840 Bytes
66df09f |
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 |
# 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!")
|