Spaces:
Sleeping
Sleeping
Deploy Naive Bayes spam classifier
Browse files- app.py +30 -0
- requirements.txt +6 -0
- spam_classifier.joblib +3 -0
- tfidf_vectorizer.joblib +3 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from joblib import load
|
| 3 |
+
import string
|
| 4 |
+
import nltk
|
| 5 |
+
from nltk.corpus import stopwords
|
| 6 |
+
|
| 7 |
+
nltk.download('stopwords')
|
| 8 |
+
|
| 9 |
+
model = load("spam_classifier.joblib")
|
| 10 |
+
vectorizer = load("tfidf_vectorizer.joblib")
|
| 11 |
+
|
| 12 |
+
def process(text):
|
| 13 |
+
nopunc = ''.join([char for char in text if char not in string.punctuation])
|
| 14 |
+
clean = [word for word in nopunc.split() if word.lower() not in stopwords.words('english')]
|
| 15 |
+
return ' '.join(clean)
|
| 16 |
+
|
| 17 |
+
def predict_email(text):
|
| 18 |
+
clean_text = process(text)
|
| 19 |
+
vect_text = vectorizer.transform([clean_text])
|
| 20 |
+
pred = model.predict(vect_text)[0]
|
| 21 |
+
return "Spam" if pred == 1 else "Not Spam"
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(fn=predict_email,
|
| 24 |
+
inputs=gr.Textbox(lines=5, placeholder='Enter email text here...'),
|
| 25 |
+
outputs='text',
|
| 26 |
+
title='Email Spam Classifier',
|
| 27 |
+
description='Predict Spam or Not Spam')
|
| 28 |
+
|
| 29 |
+
if __name__ == '__main__':
|
| 30 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=3.0
|
| 2 |
+
scikit-learn>=1.2
|
| 3 |
+
joblib>=1.3
|
| 4 |
+
nltk>=3.8
|
| 5 |
+
numpy>=1.27
|
| 6 |
+
pandas>=2.1
|
spam_classifier.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ab8d15ad10dc0b902433c14f4bc901da8af5545bc78e4b66faf3b226f0dc66ef
|
| 3 |
+
size 1190775
|
tfidf_vectorizer.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2f0b2306c207777b5bc9b4d59044321d093cda9c9f49c045c93daca4a21b9ef
|
| 3 |
+
size 781557
|