-
Notifications
You must be signed in to change notification settings - Fork 0
/
flaskapp.py
93 lines (74 loc) · 3.01 KB
/
flaskapp.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
88
89
90
91
92
93
from flask import Flask, render_template, Response,jsonify,request,session
from flask_wtf import FlaskForm
from wtforms import FileField, SubmitField,StringField,DecimalRangeField,IntegerRangeField
from werkzeug.utils import secure_filename
from wtforms.validators import InputRequired,NumberRange
import os
import cv2
from YOLO_Video import video_detection
from video_temp import video_detection_vid
app = Flask(__name__)
app.config['SECRET_KEY'] = 'maskboy'
app.config['UPLOAD_FOLDER'] = 'static/files'
class UploadFileForm(FlaskForm):
file = FileField("File",validators=[InputRequired()])
submit = SubmitField("Run")
def generate_frames(path_x = ''):
yolo_output = video_detection_vid(path_x)
for detection_ in yolo_output:
ref,buffer=cv2.imencode('.jpg',detection_)
frame=buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame +b'\r\n')
def generate_frames_web(receiver,path_x):
yolo_output = video_detection(path_x,receiver)
for detection_ in yolo_output:
ref,buffer=cv2.imencode('.jpg',detection_)
frame=buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame +b'\r\n')
@app.route('/', methods=['GET','POST'])
@app.route('/home', methods=['GET','POST'])
def home():
session.clear()
return render_template('index.html')
@app.route("/webcam", methods=['GET','POST'])
def webcam():
session.clear()
return render_template('ui.html')
@app.route('/FrontPage', methods=['GET','POST'])
def front():
form = UploadFileForm()
if form.validate_on_submit():
# Our uploaded video file path is saved here
file = form.file.data
file.save(os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'],
secure_filename(file.filename))) # Then save the file
# Use session storage to save video file path
session['video_path'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'],
secure_filename(file.filename))
return render_template('videoprojectnew.html', form=form)
@app.route('/video')
def video():
return Response(generate_frames(path_x = session.get('video_path', None)),mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/webapp')
def webapp():
email = request.args.get('email')
print(email)
return Response(generate_frames_web(email,path_x=0), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route("/signup", methods=['GET','POST'])
def signup():
session.clear()
return render_template('signup.html')
@app.route("/profile", methods=['GET','POST'])
@app.route("/profile", methods=['GET','POST'])
def profile():
session.clear()
return render_template('home.html')
@app.route("/email",methods=['GET','POST'])
def email():
email = request.form.get("email")
# print(email)
return email
if __name__ == "__main__":
app.run(debug=True)