amirsoahil101 commited on
Commit
7cd37bc
·
1 Parent(s): 0ebda96

add all files

Browse files
Files changed (4) hide show
  1. app.py +66 -0
  2. requirements.txt +11 -0
  3. spam_model.pkl +3 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+
4
+ # EX :- win big now | win free urgent offer limited limited urgent urgent free beyond baby physical environmental none meeting foreign low | unknownmail.cc
5
+ # EX :- project update | team sync president series today already involve lose control brother issue week blood firm personal let next | company.com
6
+
7
+
8
+ # Page configuration
9
+ st.set_page_config(page_title="Email Spam Detector", page_icon="📧")
10
+
11
+ # Custom CSS for styling
12
+ st.markdown("""
13
+ <style>
14
+ .main {
15
+ background-color: #f0f2f6;
16
+ }
17
+ .stButton>button {
18
+ width: 100%;
19
+ border-radius: 5px;
20
+ height: 3em;
21
+ background-color: #ff4b4b;
22
+ color: white;
23
+ }
24
+ </style>
25
+ """, unsafe_allow_html=True)
26
+
27
+ # Loading the model and vectorizer
28
+ try:
29
+ model = pickle.load(open('spam_model.pkl', 'rb'))
30
+ vectorizer = pickle.load(open('vectorizer.pkl', 'rb'))
31
+ except FileNotFoundError:
32
+ st.error("Error: 'spam_model.pkl' ya 'vectorizer.pkl' file nahi mili. Pehle model train karke save karein.")
33
+
34
+ # UI Header
35
+ st.title("📧 Email Spam Classifier")
36
+ st.write("Apna email subject aur text niche enter karein check karne ke liye.")
37
+
38
+ # Input Section
39
+ with st.container():
40
+ domain = st.text_input("Email Domain", placeholder="Write your email domain...")
41
+ subject = st.text_input("Subject", placeholder="E.g. Congratulations! You won a prize")
42
+ message = st.text_area("Email Content", placeholder="Write your email body here...", height=150)
43
+
44
+ # Prediction Logic
45
+ if st.button("Predict Now"):
46
+ if message.strip() == "":
47
+ st.warning("Please enter the email text to analyze.")
48
+ else:
49
+ # Combine subject and message (Common practice in spam detection)
50
+ full_text = subject + " " + message + " " + domain
51
+
52
+ # 1. Preprocess/Transform using vectorizer
53
+ data = vectorizer.transform([full_text])
54
+
55
+ # 2. Prediction
56
+ prediction = model.predict(data)[0]
57
+
58
+ # 3. Display Result
59
+ st.divider()
60
+ if prediction == 1: # Assuming 1 is Spam
61
+ st.error("🚨 This is a SPAM email!")
62
+ else:
63
+ st.success("✅ This is a HAM (Safe) email.")
64
+
65
+ # Footer
66
+ st.caption("Built with Python & Streamlit")
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ scikit-learn
4
+ pandas
5
+
6
+
7
+
8
+
9
+ # pickle.dump(model, open('spam_model.pkl', 'wb'))
10
+ # pickle.dump(tfidf, open('vectorizer.pkl', 'wb'))
11
+ # pickle.dump(scaler, open('scaler.pkl', 'wb'))
spam_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83383f95a37119db5a3827448067bc091aa240f4752df799031b83d302bde1ad
3
+ size 2397440
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9582049e282ba16c83b7c967e8f9f4fc450f4555d613bd667811e4f2fa966188
3
+ size 2016032