forked from MaXeraph/unzucc.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·89 lines (67 loc) · 2.67 KB
/
__init__.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os, math
from flask import Flask, render_template, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
import face_recognition
import cv2
from PIL import Image
import numpy as np
fileDir = os.path.dirname(os.path.realpath('__file__'))
UPLOAD_FOLDER = os.path.join(fileDir, 'static')
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
filename = "downloadButton.png"
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 300
def fuzz(file,faces,level):
src1 = np.array(Image.open(file))
noise = np.rint(np.random.normal(0, level, src1.shape))
mask = np.zeros(src1.shape, dtype=int)
for face in faces:
mask[face[0]:face[2], face[3]:face[1]] = noise[face[0]:face[2], face[3]:face[1]]
final = np.clip(np.absolute(np.add(mask, src1)).astype(int), 0, 255)
im = Image.fromarray(final.astype('uint8'), 'RGB')
im.save(file)
@app.route("/")
def home():
return render_template("index.html", imaging=filename)
def allowed_file(fname):
return '.' in fname and \
fname.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
data = request.form["text"]
if data == "":
mask_level = 1
else:
mask_level = abs(int(data.upper()))
# check if the post request has the file part
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
filename = file.filename
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
destination = "./static/" + filename
image = face_recognition.load_image_file("./static/"+filename)
face_locations = face_recognition.face_locations(image)
fuzz(destination, face_locations, mask_level)
return render_template("index.html", imaging=filename)
return render_template("index.html", imaging=filename)
@app.after_request
def add_header(r):
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"
r.headers['Cache-Control'] = 'public, max-age=0'
return r
if __name__ == "__main__":
app.run(debug=True)