File size: 695 Bytes
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
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(),
    outputs="text",
)
    
if __name__ == "__main__":
    iface.launch()