-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
48 lines (40 loc) · 1.62 KB
/
app.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
import os, glob, sys
from flask import Flask, send_from_directory, flash, render_template, request, send_file, redirect, url_for
from p2l import *
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = "/Users/Flamingo/Documents/Paper2LaTeX/examples"
ALLOWED_EXTENSIONS = set(['png','jpg','jpeg','gif'])
app = Flask(__name__)
app.secret_key = "p2l"
app.debug = True
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 main():
return render_template('main.html')
@app.route('/upload_photo', methods=['POST'])
def upload_photo():
if request.method == 'POST':
if 'img' not in request.files:
flash('No file selected')
return redirect(url_for('main'))
img = request.files['img']
if img and allowed_file(img.filename):
img_name = secure_filename(img.filename)
img.save(os.path.join(app.config['UPLOAD_FOLDER'], img_name))
img_nodes, img = get_semantics(img_name)
bbox_edges = make_bbox_edge_dict(img_nodes)
graph = find_edges(img, img_nodes, bbox_edges)
transpile(graph)
return redirect(url_for('uploaded_file', filename = img_name))
else:
return redirect(url_for('main'))
@app.route('/results/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)