prthgo commited on
Commit
b7e764c
1 Parent(s): cb6a76b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tfidf=pickle.load(open('tfidf.pkl','rb'))
2
+ model=pickle.load(open('model.pkl','rb'))
3
+
4
+ def classify_msg(Message):
5
+ X=preprocess(Message)
6
+ X_vector=tfidf.transform([X])
7
+ prediction=model.predict(X_vector)[0]
8
+ return 'Spam' if prediction==1 else 'Not Spam'
9
+
10
+
11
+ def preprocess(text):
12
+ text = text.lower()
13
+ tokens = nltk.word_tokenize(text)
14
+ text = []
15
+ for token in tokens:
16
+ if token not in stopwords.words('english') and token not in string.punctuation:
17
+ text.append(token)
18
+
19
+ return ' '.join(text)
20
+
21
+
22
+ iface = gr.Interface(
23
+ fn=classify_msg,
24
+ inputs=gr.inputs.Textbox(),
25
+ outputs="text",
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ iface.launch()