Skip to content

Commit 8bcd017

Browse files
update all the files for hosting on flask
1 parent 0645c5c commit 8bcd017

11 files changed

+643
-0
lines changed
1.83 KB
Binary file not shown.

__pycache__/flask_app.cpython-37.pyc

1.12 KB
Binary file not shown.

bing_detect.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import joblib
2+
import os
3+
import re
4+
from string import punctuation
5+
import time
6+
import datetime
7+
import nltk
8+
from nltk.corpus import stopwords
9+
from nltk.tokenize import word_tokenize
10+
nltk.download('stopwords')
11+
nltk.download('punkt')
12+
import sklearn
13+
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
14+
15+
16+
def clean_text(text):
17+
'''
18+
function to preprocess and clean the data before passing the data to model
19+
20+
parameters :
21+
text (str) : raw unprocessed text
22+
23+
returns :
24+
text (str) : preprocessed text ready to be passed onto the model pipeline
25+
'''
26+
STOPWORDS = set(stopwords.words('english'))
27+
text = text.lower()
28+
text = re.compile('[/(){}\[\]\|@,;]').sub(' ', text)
29+
text = re.compile('[^0-9a-z #+_]').sub('', text)
30+
text = ' '.join(word for word in text.split() if word not in STOPWORDS and word not in punctuation and len(word) > 2)
31+
return text
32+
33+
def detect_bing(input_query, model_path):
34+
'''
35+
main function for getting the predictions back to the flask app
36+
37+
parameters :
38+
args :
39+
input_query (str) : url input by the user on the home page
40+
'''
41+
42+
43+
print(input_query)
44+
model = joblib.load(model_path)
45+
cleaned_text = clean_text(input_query)
46+
print(cleaned_text)
47+
result = model.predict([cleaned_text])
48+
return result

flask_app.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from flask import Flask, render_template, request
2+
from bing_detect import detect_bing
3+
from PIL import Image
4+
import io
5+
import numpy as np
6+
import os
7+
8+
9+
app = Flask(__name__, static_folder="images")
10+
11+
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
12+
target = os.path.join(APP_ROOT, 'images/')
13+
full_path = target + 'result.png'
14+
15+
@app.route('/bing_search', methods = ['GET','POST'])
16+
def Bing_detection():
17+
'''
18+
Routing Bing search detection APP
19+
Methods permitted : GET, POST
20+
'''
21+
if request.method == 'GET':
22+
return render_template('index_bing.html')
23+
24+
if request.method == 'POST':
25+
X = request.form['xname']
26+
if not X or X == '':
27+
return render_template('error_bing.html', message='EMPTY_URL_ERROR : please enter something !')
28+
29+
model_path = APP_ROOT + '/model.pkl'
30+
print(X)
31+
print(model_path)
32+
prediction = detect_bing(X, model_path)
33+
print(prediction)
34+
prediction_list = [X, prediction]
35+
return render_template('result_bing.html', prediction_list=prediction_list)

model.pkl

899 KB
Binary file not shown.

static/1.jpg

289 KB
Loading

static/logo.jpg

5.18 KB
Loading

templates/error_bing.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!-- Latest compiled and minified CSS -->
5+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
6+
7+
<!-- jQuery library -->
8+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
9+
10+
<!-- Latest compiled JavaScript -->
11+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
12+
13+
<link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap" rel="stylesheet">
14+
<title>Object Detection App</title>
15+
16+
<style>
17+
/* nav bar starts */
18+
ul {
19+
list-style-type: none;
20+
margin: 0;
21+
padding: 0;
22+
overflow: hidden;
23+
background-color: #333;
24+
}
25+
26+
li {
27+
float: left;
28+
}
29+
30+
li a {
31+
display: block;
32+
color: white;
33+
text-align: center;
34+
padding: 14px 16px;
35+
text-decoration: none;
36+
}
37+
38+
li a:hover:not(.active) {
39+
background-color: #111;
40+
}
41+
42+
.active {
43+
background-color: #ed561a;
44+
}
45+
/* nav bar finished */
46+
h1{font-family: 'Amatic SC', cursive;
47+
text-align: center;}
48+
h3{text-align: center;}
49+
.footer {
50+
position: fixed;
51+
left: 0;
52+
bottom: 0;
53+
width: 100%;
54+
background-color: #fc7419;
55+
color: white;
56+
text-align: center;
57+
}
58+
@media only screen and (max-width: 768px) {
59+
h1{font-family: 'Amatic SC', cursive;
60+
text-align: center;}
61+
h3{text-align: center;}
62+
}
63+
</style>
64+
</head>
65+
<body background="/static/1.jpg">
66+
<ul>
67+
<li><a class="active" href="/bing_search">Home</a></li>
68+
</ul>
69+
<div class="container">
70+
<br><br><br><br>
71+
<div class = "row">
72+
<h1 style="font-size:15vw;">ERROR : 4 0 4</h1>
73+
</div>
74+
<div class = "row">
75+
<h3>{{ message }}</h3>
76+
</div>
77+
</div>
78+
<div class="footer">
79+
<p>MADE BY SOURAV KUMAR</p>
80+
</div>
81+
82+
</body>
83+
</html>

templates/index.html

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta http-equiv="x-ua-compatible" content="ie=edge">
7+
<meta name="description" content="Real time Object detection, Real time Edge detection, Computer vision Projects, Machine learning, Deep learning">
8+
<link rel="icon" type="image/ico" href="/static/logo.jpg" />
9+
<!-- Latest compiled and minified CSS -->
10+
11+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
12+
13+
<link href="https://fonts.googleapis.com/css2?family=Capriola&display=swap" rel="stylesheet">
14+
<!-- jQuery library -->
15+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
16+
17+
<!-- Latest compiled JavaScript -->
18+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
19+
20+
21+
<title>SOURAV KUMAR ML/DL PROJECTS</title></head>
22+
<style>
23+
/* nav bar starts */
24+
ul {
25+
list-style-type: none;
26+
margin: 0;
27+
padding: 0;
28+
overflow: hidden;
29+
background-color: #333;
30+
}
31+
32+
li {
33+
float: left;
34+
}
35+
36+
li a {
37+
display: block;
38+
color: white;
39+
text-align: center;
40+
padding: 14px 16px;
41+
text-decoration: none;
42+
}
43+
44+
li a:hover:not(.active) {
45+
background-color: #111;
46+
}
47+
48+
.active {
49+
background-color: #ed561a;
50+
}
51+
/* nav bar finished */
52+
53+
button {
54+
border-radius: 4px;
55+
background-color:#ffa557;
56+
border: none;
57+
padding: 20px;
58+
width: 200px;
59+
transition: all 0.5s;
60+
}
61+
62+
63+
button span {
64+
cursor: pointer;
65+
display: inline-block;
66+
position: relative;
67+
transition: 0.5s;
68+
}
69+
70+
button span:after {
71+
content: '»';
72+
position: absolute;
73+
opacity: 0;
74+
top: 0;
75+
right: -20px;
76+
transition: 0.5s;
77+
}
78+
79+
button:hover span {
80+
padding-right: 25px;
81+
}
82+
83+
button:hover span:after {
84+
opacity: 1;
85+
right: 0;
86+
}
87+
.sub-main{
88+
width: 30%;
89+
margin:22px;
90+
float: left;
91+
}
92+
93+
94+
.footer {
95+
position: fixed;
96+
left: 0;
97+
bottom: 0;
98+
width: 100%;
99+
background-color: #fc7419;
100+
color: white;
101+
text-align: center;
102+
}
103+
h2 {text-align: center;
104+
font-family: 'Capriola', sans-serif; }
105+
106+
form{
107+
display: inline-block;
108+
}
109+
.object-btn-container{
110+
text-align: center;
111+
}
112+
.edge-btn-container{
113+
text-align: center;
114+
}
115+
.flair-btn-container{
116+
text-align: center;
117+
}
118+
119+
120+
@media only screen and (max-width: 768px) {
121+
122+
123+
}
124+
</style>
125+
<body background="/static/1.jpg">
126+
<ul>
127+
<li><a class="active" href="/">Home</a></li>
128+
</ul>
129+
<div class="container">
130+
131+
132+
<br>
133+
<h2>WELCOME TO DIMENSIONS.AI</h2>
134+
<br><br><br>
135+
136+
<div class = 'object-btn-container'>
137+
<form action="/object">
138+
<div class = "sub-main">
139+
<button id="objectbtn" type="submit">Object Detection</button>
140+
</div>
141+
</form>
142+
</div>
143+
<br>
144+
<div class = 'edge-btn-container'>
145+
<form action="/edge">
146+
<div class = "sub-main">
147+
<button id="edgebtn" type="submit">Edge Detection</button>
148+
</div>
149+
</form>
150+
</div>
151+
<br>
152+
153+
154+
155+
<div class="footer">
156+
<p>MADE BY SOURAV KUMAR</p>
157+
</div>
158+
159+
</div>
160+
161+
</body>
162+
</html>

0 commit comments

Comments
 (0)