File size: 1,033 Bytes
7669dc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
import streamlit as st
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer 

# Load the SVM model
with open('svm_model.pkl', 'rb') as model_file:
    svm_model = pickle.load(model_file)

# Load the vectorizer used during training
with open('vectorize.pkl', 'rb') as vectorizer_file:
    vectorizer = pickle.load(vectorizer_file)

# Function to preprocess and classify messages
def classify_message(message):
    # Preprocess the message using the vectorizer
    message_vectorized = vectorizer.transform([message])
    # Predict using the SVM model
    prediction = svm_model.predict(message_vectorized)[0]
    return prediction

# Streamlit app
def main():
    st.title('Spam Filter')
    message = st.text_area('Enter your message here:')
    
    if st.button('Predict'):
        if message:
            prediction = classify_message(message)
            st.write(f'Prediction: {prediction}')
        else:
            st.warning('Please enter a message to classify.')

if __name__ == '__main__':
    main()