Commit ·
7cd37bc
1
Parent(s): 0ebda96
add all files
Browse filesFiles changed (4)
- app.pyAdded+66
- requirements.txtAdded+11
- spam_model.pklAdded+3
- vectorizer.pklAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import streamlit as stimport pickle
# EX :- win big now | win free urgent offer limited limited urgent urgent free beyond baby physical environmental none meeting foreign low | unknownmail.cc# EX :- project update | team sync president series today already involve lose control brother issue week blood firm personal let next | company.com
# Page configurationst.set_page_config(page_title="Email Spam Detector", page_icon="📧")
# Custom CSS for stylingst.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)
# Loading the model and vectorizertry: 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.")
# UI Headerst.title("📧 Email Spam Classifier")st.write("Apna email subject aur text niche enter karein check karne ke liye.")
# Input Sectionwith 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)
# Prediction Logicif st.button("Predict Now"): if message.strip() == "": st.warning("Please enter the email text to analyze.") else: # Combine subject and message (Common practice in spam detection) full_text = subject + " " + message + " " + domain # 1. Preprocess/Transform using vectorizer data = vectorizer.transform([full_text]) # 2. Prediction prediction = model.predict(data)[0] # 3. Display Result st.divider() if prediction == 1: # Assuming 1 is Spam st.error("🚨 This is a SPAM email!") else: st.success("✅ This is a HAM (Safe) email.")
# Footerst.caption("Built with Python & Streamlit")1234567891011streamlitnumpyscikit-learnpandas
# pickle.dump(model, open('spam_model.pkl', 'wb'))# pickle.dump(tfidf, open('vectorizer.pkl', 'wb'))# pickle.dump(scaler, open('scaler.pkl', 'wb'))123version https://git-lfs.github.com/spec/v1oid sha256:83383f95a37119db5a3827448067bc091aa240f4752df799031b83d302bde1adsize 2397440123version https://git-lfs.github.com/spec/v1oid sha256:9582049e282ba16c83b7c967e8f9f4fc450f4555d613bd667811e4f2fa966188size 2016032app.pyAdded+66
requirements.txtAdded+11
spam_model.pklAdded+3
vectorizer.pklAdded+3