-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathupload_student.py
64 lines (46 loc) · 2.05 KB
/
upload_student.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
import os
from app import app
import urllib.request
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from student_test import testImage, getFaces
from mark import markAttendance
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def upload_form():
return render_template('upload.html')
@app.route('/', methods=['POST'])
def upload_image():
# Function to upload an image. You can upload images from test folder or from the internet and classify them.
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash('Image successfully uploaded and displayed below')
# caption = testImage({"image":"static/uploads/{}".format(filename)})
# return render_template('upload.html', filename=filename,caption=caption)
# Using the getFaces function to get all different faces from the uploaded image
faces = getFaces("static/uploads/{}".format(filename))
# Using the markAttendance function to mark attendance of recognized faces.
attendance = markAttendance(faces,own=True).drop_duplicates()
htl = attendance.to_html() # convert to html so as to render in the
print(attendance.to_html())
return render_template('upload.html', filename=filename,htl=htl)
else:
flash('Allowed image types are -> png, jpg, jpeg, gif')
return redirect(request.url)
@app.route('/display/<filename>')
def display_image(filename):
# Function to display uploaded image
print("Display image called")
return redirect(url_for('static', filename='uploads/' + filename), code=301)
if __name__ == "__main__":
app.run(debug=True)