File size: 978 Bytes
e337348
 
 
 
 
 
 
da76625
 
e337348
b7e764c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c47f71b
b7e764c
 
 
 
 
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
import gradio as gr
import pickle
import nltk
from nltk.corpus import stopwords
import string
from sklearn.feature_extraction.text import  TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
nltk.download('punkt')
nltk.download('stopwords')

tfidf=pickle.load(open('tfidf.pkl','rb'))
model=pickle.load(open('model.pkl','rb'))

def classify_msg(Message):
    X=preprocess(Message)
    X_vector=tfidf.transform([X])
    prediction=model.predict(X_vector)[0]
    return 'Spam' if prediction==1 else 'Not Spam'
    
    
def preprocess(text):
    text = text.lower()
    tokens = nltk.word_tokenize(text)
    text = []
    for token in tokens:
        if token not in stopwords.words('english') and token not in string.punctuation:
            text.append(token)

    return ' '.join(text)


iface = gr.Interface(
    fn=classify_msg,
    inputs=gr.inputs.Textbox(placeholder='Type Message Here'),
    outputs="text",
)
    
if __name__ == "__main__":
    iface.launch()