-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (50 loc) · 1.72 KB
/
app.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, render_template, request, jsonify
import pickle
from gingerit.gingerit import GingerIt
import re
app = Flask(__name__)
parser = GingerIt()
@app.route("/", methods=["GET", "POST"])
def index():
message = request.form.get("message")
result = is_spam(message)
if request.method == "POST":
return render_template("check.html", message=result)
return render_template("index.html")
@app.route("/HashedboticsAPI/<text>")
def HashedboticsAPI(text):
result = is_spam(text)
return jsonify(result)
def is_spam(text):
with open('model_pickle', "rb") as f:
imported_model = pickle.load(f)
text = str(text).lower()
result = imported_model.predict([f"{text}"])
if result[0] == 1:
return "spam!"
li = re.findall(r"[\w']+", text)
long_words = ["thiruvananthapuram",
"pneumonoultramicroscopicsilicovolcanoconiosis",
"hippopotomonstrosesquippedaliophobia",
"supercalifragilisticexpialidocious",
"pseudopseudohypoparathyroidism",
"floccinaucinihilipilification",
"antidisestablishmentarianism",
"honorificabilitudinitatibus",
"thyroparathyroidectomized",
"dichlorodifluoromethane",
"incomprehensibilities"]
for i in li:
if len(i) >= 19:
if i not in long_words:
return "spam!"
elif i == "binod":
return "spam!"
try:
for i in li:
if parser.parse(i)["corrections"][0]["definition"] is None:
return "spam!"
except:
return "not spam."
if __name__ == "__main__":
app.run(debug=True)