-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.py
73 lines (58 loc) · 2.17 KB
/
serve.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
import os
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from extract import ext
UPLOAD_FOLDER = 'static'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'mp4'}
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
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 == '':
flash('No selected file')
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))
return redirect(url_for('process')) #this points to the next page
return render_template('index.html')
@app.route('/process', methods=['GET', 'POST'])
def process():
ext()
return render_template('splashscreen.html')
@app.route('/sf', methods=['GET'])
def showImg():
return render_template('postupload.html')
app.run(debug=True)
# Candidate main server
'''
To do:
1. Main page to upload a photo
2. Run the DL model and create rectangles
3. Take that image and generate the output
'''
# from flask import Flask, render_template, request
# from werkzeug.utils import secure_filename
# app = Flask(__name__)
# @app.route('/')
# def upload_file():
# return render_template('upload.html')
# @app.route('/uploader', methods = ['GET', 'POST'])
# def uploader():
# if request.method == 'POST':
# f = request.files['file']
# f.save(secure_filename(f.filename))
# return 'file uploaded successfully'
# if __name__ == '__main__':
# app.run(debug = True)