prthgo's picture
Create app.py
b7e764c
raw
history blame
695 Bytes
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()