Skip to content

Commit 37db55b

Browse files
authored
Add files via upload
0 parents  commit 37db55b

File tree

11 files changed

+23099
-0
lines changed

11 files changed

+23099
-0
lines changed

data/data.csv

Lines changed: 5573 additions & 0 deletions
Large diffs are not rendered by default.

data/spam.csv

Lines changed: 5575 additions & 0 deletions
Large diffs are not rendered by default.

data/spam__detector.sql

Lines changed: 11231 additions & 0 deletions
Large diffs are not rendered by default.

main.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from flask import Flask, render_template, request
2+
from flask_sqlalchemy import SQLAlchemy
3+
# import pandas as pd
4+
import pymysql
5+
6+
pymysql.install_as_MySQLdb()
7+
8+
app = Flask(__name__)
9+
db = SQLAlchemy(app)
10+
app.secret_key = 'my precious'
11+
12+
# connect flask sqlalchemy to app
13+
db_user = "root"
14+
db_password = ""
15+
db_host = "localhost"
16+
db_name = "spam_detector"
17+
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://' + db_user + ':' + db_password + '@' + db_host + '/' + db_name
18+
19+
20+
class Spam_Detector(db.Model):
21+
d_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
22+
spam_or_ham = db.Column(db.String(11), unique=False, nullable=False)
23+
data = db.Column(db.String(1000), unique=False, nullable=False)
24+
25+
26+
db.create_all()
27+
28+
29+
# f = pd.read_csv("data/data.csv" ,encoding='latin1')
30+
#
31+
# for index in f.index:
32+
# spam_or_ham = f["spam_or_ham"][index]
33+
# data = f["data"][index]
34+
#
35+
# d = Spam_Detector(spam_or_ham = spam_or_ham , data=data)
36+
# db.session.add(d)
37+
# db.session.commit()
38+
39+
@app.route("/", methods=["GET", 'POST'])
40+
def home():
41+
return render_template("home.html")
42+
43+
44+
@app.route("/result", methods=['POST'])
45+
def homer():
46+
user_input = request.form.get("user_input")
47+
search = "%{}%".format(user_input)
48+
fetched_data = Spam_Detector.query.filter(Spam_Detector.data.like(search)).all()
49+
spam_count = 0
50+
ham_count = 0
51+
for data in fetched_data:
52+
if data.spam_or_ham == "spam":
53+
spam_count += 1
54+
else:
55+
ham_count += 1
56+
57+
numerator = 0
58+
denominator = 0
59+
if spam_count > ham_count:
60+
numerator = ham_count
61+
denominator = spam_count
62+
else:
63+
numerator = spam_count
64+
denominator = ham_count
65+
66+
try:
67+
spam_per = abs(((numerator / denominator) * 100))
68+
except:
69+
spam_per = 0
70+
71+
if spam_count > ham_count:
72+
spam_per = abs(spam_per - 100)
73+
spam_per = round(spam_per, 2)
74+
ham_per = round(abs(spam_per - 100), 2)
75+
return render_template("result.html", spam_count=spam_count, ham_count=ham_count, spam_per=spam_per,
76+
ham_per=ham_per)
77+
78+
79+
@app.route("/about", methods=['GET', 'POST'])
80+
def about():
81+
return render_template("about.html")
82+
83+
84+
app.run(debug=True, host="0.0.0.0")

requirements.txt

554 Bytes
Binary file not shown.

static/images/spam_filter.png

121 KB
Loading

static/main.bff24adf2375a62a4452.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/style.b973ef58d3fd736d16d2.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/about.html

Lines changed: 241 additions & 0 deletions
Large diffs are not rendered by default.

templates/home.html

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<!DOCTYPE html>
2+
<html lang="en" class="">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Spam Detector</title>
6+
<script>
7+
if (localStorage.getItem('dark-mode') == 'true' || !('dark-mode' in localStorage)) {
8+
document.querySelector('html').classList.add('dark');
9+
} else {
10+
document.querySelector('html').classList.remove('dark');
11+
}
12+
</script>
13+
<link href="static/style.b973ef58d3fd736d16d2.css" rel="stylesheet">
14+
</head>
15+
<body class="pa dh ly pj me mw pk">
16+
<!-- Page wrapper -->
17+
<div class="uh fp ao lu">
18+
<!-- Site header -->
19+
<header class="ii au ib">
20+
<div class="ax ss ht yo">
21+
<div class="uh fm fw ae">
22+
<div class="fr om"> <a class="ul" href="/" aria-label="Cruip"> <svg class="ap uj"
23+
viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
24+
<defs>
25+
<linearGradient x1="26%" y1="100%" x2="100%" y2="100%" id="logo_a">
26+
<stop stop-color="#3ABAB4" offset="0%"></stop>
27+
<stop stop-color="#7F9CF5" offset="100%"></stop>
28+
</linearGradient>
29+
<linearGradient x1="26%" y1="100%" x2="100%" y2="100%" id="logo_b">
30+
<stop stop-color="#3ABAB4" offset="0%"></stop>
31+
<stop stop-color="#3ABAB4" stop-opacity="0" offset="100%"></stop>
32+
</linearGradient>
33+
</defs>
34+
<path d="M32 16h-8a8 8 0 10-16 0H0C0 7.163 7.163 0 16 0s16 7.163 16 16z"
35+
fill="url(#logo_a)"></path>
36+
<path d="M32 16c0 8.837-7.163 16-16 16S0 24.837 0 16h8a8 8 0 1016 0h8z"
37+
fill="url(#logo_b)"></path>
38+
</svg> </a> </div>
39+
<nav class="uv bn bp">
40+
<ul class="uh fi fd fm pv">
41+
<li> <a class="text-gray-600 vp dark--text-gray-300 ga hh ho uh fm d_ dz vr"
42+
href="/">HOME</a> </li>
43+
<li> <a class="text-gray-600 vp dark--text-gray-300 ga hh ho uh fm d_ dz vr"
44+
href="/about">ABOUT</a> </li>
45+
</ul>
46+
<div class="form-switch uh fp fb sx"> <input type="checkbox" name="light-switch"
47+
id="light-switch-desktop" class="light-switch it"> <label class="is"
48+
for="light-switch-desktop"> <span class="is ce co cv mf mb rc iw"
49+
aria-hidden="true"></span> <svg class="ii io" width="44" height="24"
50+
viewBox="0 0 44 24" xmlns="http://www.w3.org/2000/svg">
51+
<g class="cx text-white" fill-rule="nonzero" opacity=".88">
52+
<path
53+
d="M32 8a.5.5 0 00.5-.5v-1a.5.5 0 10-1 0v1a.5.5 0 00.5.5zM35.182 9.318a.5.5 0 00.354-.147l.707-.707a.5.5 0 00-.707-.707l-.707.707a.5.5 0 00.353.854zM37.5 11.5h-1a.5.5 0 100 1h1a.5.5 0 100-1zM35.536 14.829a.5.5 0 00-.707.707l.707.707a.5.5 0 00.707-.707l-.707-.707zM32 16a.5.5 0 00-.5.5v1a.5.5 0 101 0v-1a.5.5 0 00-.5-.5zM28.464 14.829l-.707.707a.5.5 0 00.707.707l.707-.707a.5.5 0 00-.707-.707zM28 12a.5.5 0 00-.5-.5h-1a.5.5 0 100 1h1a.5.5 0 00.5-.5zM28.464 9.171a.5.5 0 00.707-.707l-.707-.707a.5.5 0 00-.707.707l.707.707z">
54+
</path>
55+
<circle cx="32" cy="12" r="3"></circle>
56+
<circle fill-opacity=".4" cx="12" cy="12" r="6"></circle>
57+
<circle fill-opacity=".88" cx="12" cy="12" r="3"></circle>
58+
</g>
59+
</svg> <span class="it">Switch to light / dark version</span> </label> </div>
60+
</nav>
61+
<div class="up bi" x-data="{ expanded: false }">
62+
<div class="form-switch uh fp fb ob ow"> <input type="checkbox" name="light-switch"
63+
id="light-switch-mobile" class="light-switch it"> <label class="is"
64+
for="light-switch-mobile"> <span class="is ce co cv mf mb rc iw"
65+
aria-hidden="true"></span> <svg class="ii io" width="44" height="24"
66+
viewBox="0 0 44 24" xmlns="http://www.w3.org/2000/svg">
67+
<g class="cx text-white" fill-rule="nonzero" opacity=".88">
68+
<path
69+
d="M32 8a.5.5 0 00.5-.5v-1a.5.5 0 10-1 0v1a.5.5 0 00.5.5zM35.182 9.318a.5.5 0 00.354-.147l.707-.707a.5.5 0 00-.707-.707l-.707.707a.5.5 0 00.353.854zM37.5 11.5h-1a.5.5 0 100 1h1a.5.5 0 100-1zM35.536 14.829a.5.5 0 00-.707.707l.707.707a.5.5 0 00.707-.707l-.707-.707zM32 16a.5.5 0 00-.5.5v1a.5.5 0 101 0v-1a.5.5 0 00-.5-.5zM28.464 14.829l-.707.707a.5.5 0 00.707.707l.707-.707a.5.5 0 00-.707-.707zM28 12a.5.5 0 00-.5-.5h-1a.5.5 0 100 1h1a.5.5 0 00.5-.5zM28.464 9.171a.5.5 0 00.707-.707l-.707-.707a.5.5 0 00-.707.707l.707.707z">
70+
</path>
71+
<circle cx="32" cy="12" r="3"></circle>
72+
<circle fill-opacity=".4" cx="12" cy="12" r="6"></circle>
73+
<circle fill-opacity=".88" cx="12" cy="12" r="3"></circle>
74+
</g>
75+
</svg> <span class="it">Switch to light / dark version</span> </label> </div> <button
76+
class="rv" :class="{ 'active': expanded }" @click.stop="expanded = !expanded"
77+
aria-controls="mobile-nav" :aria-expanded="expanded"> <span class="it">Menu</span> <svg
78+
class="ad uq cx pj vp dark--text-gray-300 ga d_ dz vr" viewBox="0 0 24 24"
79+
xmlns="http://www.w3.org/2000/svg">
80+
<rect y="4" width="24" height="2" rx="1"></rect>
81+
<rect y="11" width="24" height="2" rx="1"></rect>
82+
<rect y="18" width="24" height="2" rx="1"></rect>
83+
</svg> </button>
84+
<nav id="mobile-nav" class="ir ip at iy if au fe ok la ly me rl rd"
85+
@click.outside="expanded = false" @keydown.escape.window="expanded = false"
86+
x-show="expanded" x-transition:enter="d_ vi vt nv" x-transition:enter-start="db na"
87+
x-transition:enter-end="opacity--100 nm" x-transition:leave="d_ vi vt"
88+
x-transition:leave-start="opacity--100" x-transition:leave-end="db" x-cloak="">
89+
<div class="hp hj hq"> <svg class="ap uj" viewBox="0 0 32 32"
90+
xmlns="http://www.w3.org/2000/svg">
91+
<defs>
92+
<linearGradient x1="26%" y1="100%" x2="100%" y2="100%" id="menulogo_a">
93+
<stop stop-color="#3ABAB4" offset="0%"></stop>
94+
<stop stop-color="#7F9CF5" offset="100%"></stop>
95+
</linearGradient>
96+
<linearGradient x1="26%" y1="100%" x2="100%" y2="100%" id="menulogo_b">
97+
<stop stop-color="#3ABAB4" offset="0%"></stop>
98+
<stop stop-color="#3ABAB4" stop-opacity="0" offset="100%"></stop>
99+
</linearGradient>
100+
</defs>
101+
<path d="M32 16h-8a8 8 0 10-16 0H0C0 7.163 7.163 0 16 0s16 7.163 16 16z"
102+
fill="url(#menulogo_a)"></path>
103+
<path d="M32 16c0 8.837-7.163 16-16 16S0 24.837 0 16h8a8 8 0 1016 0h8z"
104+
fill="url(#menulogo_b)"></path>
105+
</svg>
106+
<ul>
107+
<br>
108+
<li> <a class="uh text-gray-600 vp dark--text-gray-300 ga ho" href="/">HOME</a>
109+
</li>
110+
<li> <a class="uh text-gray-600 vp dark--text-gray-300 ga ho"
111+
href="/about">ABOUT</a> </li>
112+
</ul>
113+
</div>
114+
</nav>
115+
</div>
116+
</div>
117+
</div>
118+
</header>
119+
<br><br>
120+
<!-- Page content -->
121+
<main class="fi">
122+
<!-- Page illustration -->
123+
<div class="is ax ss um in ig" aria-hidden="true">
124+
<svg class="ii ip il nv ng ur gt" width="800" height="502" fill="none"
125+
xmlns="http://www.w3.org/2000/svg">
126+
<circle cx="400" cy="102" r="400" fill="url(#heroglow_paint0_radial)" fill-opacity=".6"></circle>
127+
<circle cx="209" cy="289" r="170" fill="url(#heroglow_paint1_radial)" fill-opacity=".4"></circle>
128+
<defs>
129+
<radialGradient id="heroglow_paint0_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse"
130+
gradientTransform="rotate(90 149 251) scale(315.089)">
131+
<stop stop-color="#3ABAB4"></stop>
132+
<stop offset="1" stop-color="#3ABAB4" stop-opacity=".01"></stop>
133+
</radialGradient>
134+
<radialGradient id="heroglow_paint1_radial" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse"
135+
gradientTransform="rotate(90 -40 249) scale(133.913)">
136+
<stop stop-color="#667EEA"></stop>
137+
<stop offset="1" stop-color="#667EEA" stop-opacity=".01"></stop>
138+
</radialGradient>
139+
</defs>
140+
</svg>
141+
</div>
142+
<!-- Page sections -->
143+
<section>
144+
<div class="ax ss ht yo">
145+
<div class="pn wi" style="margin-top:50px">
146+
<div class="br bm bw xw fm">
147+
<div class="ym wd sp yx po wo">
148+
<h1 class="h1 ke sm pf pg" data-aos="fade-down">Spam or Ham</h1>
149+
<p class="pl text-gray-600 dark--text-gray-400" data-aos="fade-down"
150+
data-aos-delay="150">Classify the Message,SMS,Email in One-Click</p>
151+
<form class="os" data-aos="fade-down" data-aos-delay="300" method="post"
152+
action="/result">
153+
<div class="uh fp yt fb fe ss gq yw">
154+
<textarea type="tel" class="ri au sw gd gv" name="user_input"
155+
placeholder="Text here" required></textarea>
156+
<button type="submit" class="re text-white bg-teal-500 vu fr" href="#0">Spam or
157+
Ham</button>
158+
</div>
159+
</form>
160+
<ul class="fe gq ss bc text-gray-600 dark--text-gray-400 os oq" data-aos="fade-down"
161+
data-aos-delay="450">
162+
<li class="uh fm sw"> <svg class="aa ug cx text-teal-400 oj fr" viewBox="0 0 12 12"
163+
xmlns="http://www.w3.org/2000/svg">
164+
<path
165+
d="M10.28 2.28L3.989 8.575 1.695 6.28A1 1 0 00.28 7.695l3 3a1 1 0 001.414 0l7-7A1 1 0 0010.28 2.28z">
166+
</path>
167+
</svg> <span>Classify Spam or Ham!</span> </li>
168+
<li class="uh fm sw"> <svg class="aa ug cx text-teal-400 oj fr" viewBox="0 0 12 12"
169+
xmlns="http://www.w3.org/2000/svg">
170+
<path
171+
d="M10.28 2.28L3.989 8.575 1.695 6.28A1 1 0 00.28 7.695l3 3a1 1 0 001.414 0l7-7A1 1 0 0010.28 2.28z">
172+
</path>
173+
</svg> <span>Get Accuracy!</span> </li>
174+
<li class="uh fm sw"> <svg class="aa ug cx text-teal-400 oj fr" viewBox="0 0 12 12"
175+
xmlns="http://www.w3.org/2000/svg">
176+
<path
177+
d="M10.28 2.28L3.989 8.575 1.695 6.28A1 1 0 00.28 7.695l3 3a1 1 0 001.414 0l7-7A1 1 0 0010.28 2.28z">
178+
</path>
179+
</svg> <span>Classify in Single Click!</span> </li>
180+
</ul>
181+
</div>
182+
<div class="yg wv po wu" x-data="{ modalExpanded: false }" data-aos="fade-up"
183+
data-aos-delay="450">
184+
<div class="up is fb fm">
185+
<img width="544" height="674" aria-hidden="true" style="opacity:0">
186+
<img class="ii" src="static/images/spam_filter.png"
187+
style="max-width:150%; margin-top:-60px">
188+
</a>
189+
</div>
190+
</div>
191+
</div>
192+
</div>
193+
</div>
194+
</section>
195+
</main>
196+
</div>
197+
<script src="static/main.bff24adf2375a62a4452.js"></script>
198+
</body>
199+
</html>

0 commit comments

Comments
 (0)