-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.py
51 lines (41 loc) · 1.68 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
49
50
51
from flask import Flask, render_template, request, flash
from werkzeug.utils import secure_filename
from pathlib import Path
import os
import cv2
from resize_for_detection import crop
import json
app = Flask(__name__)
app.config["IMAGE_UPLOADS"] = "F:/Bino/Tensorflow/models/research/object_detection/static/uploads/"
app.secret_key = 'secret123'
@app.route('/', methods=["GET", "POST"])
def index():
if request.method == "POST":
if 'image' in request.files:
image = request.files["image"]
filename = secure_filename(image.filename)
filepath = os.path.join(app.config['IMAGE_UPLOADS'], filename)
image.save(filepath)
image = cv2.imread(filepath)
flash('Generated Successfully!', 'success')
crop(filepath, filename, image)
html_file = Path(filename).stem + ".html"
output_file_path = os.path.join("static/output", html_file)
if os.path.exists(output_file_path):
with open(output_file_path, "r") as f:
code = f.read()
else:
code = "The file does not exist"
return render_template('home.html', display_detection=filename, fname=filename, code=code, html_file=html_file)
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/output')
def output():
data = []
with open('static/json/sorted/sorted_data.json') as f:
data = json.load(f)
return render_template('output.html', len=len(data), data=data)
if __name__ == '__main__':
app.run(debug=True)