-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (43 loc) · 2.05 KB
/
app.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import streamlit as st
import joblib
from PIL import Image
from spam_emails import spam_emails
from non_spam_emails import non_spam_emails
def classify_email(test_input):
input_data_features = tfidf_vectorizer.transform([test_input])
prediction = model.predict(input_data_features)
return prediction[0]
# Navigation Bar
nav_selection = st.sidebar.radio("Navigation", ["Home", "Spam Email List", "Not Spam Email List"])
if nav_selection == "Spam Email List":
st.header("Spam Email List")
for email in spam_emails:
st.code(email)
elif nav_selection == "Not Spam Email List":
st.header("Not Spam Email List")
for email in non_spam_emails:
st.code(email)
else:
st.write('<h3>Email Spam Classification <span style="color:#EE7214;">(Logistic Regression)</span></h3>', unsafe_allow_html=True)
st.caption('Empower Your Inbox: Effortlessly Distinguish Spam from Legitimate Emails with our Email Spam Classification Tool')
# Loading the trained Logistic Regression model
model = joblib.load('models/email_model.pkl')
# Loading the TF-IDF vectorizer from the file
tfidf_vectorizer = joblib.load('models/tfidf_vectorizer.pkl')
# Getting the user input
input_text = st.text_area("Enter an email text to classify:", max_chars=500)
if st.button("Classify"):
if input_text:
result = classify_email(input_text)
if result == 1:
background = Image.open("assets/alert.png")
col1, col2, col3 = st.columns(3)
col2.image(background, use_column_width=True, width=10)
st.write("Prediction:", "<b style='color:#FC4100;'>Spam Eamil</b>", unsafe_allow_html=True)
else:
background = Image.open("assets/ok.png")
col1, col2, col3 = st.columns(3)
col2.image(background, use_column_width=True, width=10)
st.write("Prediction:", "<b style='color:#65B741;'>None Spam Email</b>", unsafe_allow_html=True)
else:
st.warning("Please enter some text to classify.")