| import streamlit as st |
| import pickle |
|
|
| |
| |
|
|
|
|
| |
| st.set_page_config(page_title="Email Spam Detector", page_icon="📧") |
|
|
| |
| st.markdown(""" |
| <style> |
| .main { |
| background-color: #f0f2f6; |
| } |
| .stButton>button { |
| width: 100%; |
| border-radius: 5px; |
| height: 3em; |
| background-color: #ff4b4b; |
| color: white; |
| } |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| try: |
| model = pickle.load(open('spam_model.pkl', 'rb')) |
| vectorizer = pickle.load(open('vectorizer.pkl', 'rb')) |
| except FileNotFoundError: |
| st.error("Error: 'spam_model.pkl' ya 'vectorizer.pkl' file nahi mili. Pehle model train karke save karein.") |
|
|
| |
| st.title("📧 Email Spam Classifier") |
| st.write("Apna email subject aur text niche enter karein check karne ke liye.") |
|
|
| |
| with st.container(): |
| domain = st.text_input("Email Domain", placeholder="Write your email domain...") |
| subject = st.text_input("Subject", placeholder="E.g. Congratulations! You won a prize") |
| message = st.text_area("Email Content", placeholder="Write your email body here...", height=150) |
|
|
| |
| if st.button("Predict Now"): |
| if message.strip() == "": |
| st.warning("Please enter the email text to analyze.") |
| else: |
| |
| full_text = subject + " " + message + " " + domain |
| |
| |
| data = vectorizer.transform([full_text]) |
| |
| |
| prediction = model.predict(data)[0] |
| |
| |
| st.divider() |
| if prediction == 1: |
| st.error("🚨 This is a SPAM email!") |
| else: |
| st.success("✅ This is a HAM (Safe) email.") |
|
|
| |
| st.caption("Built with Python & Streamlit") |