-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (35 loc) · 1.05 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
import flask
from flask import request, redirect
from flask_cors import CORS
import os.path
import draw_inference
import dng2png
app = flask.Flask(__name__)
app.config["DEBUG"] = True
CORS(app)
@app.route('/', methods=['GET'])
def homepage():
with open('index.html') as f:
return f.read()
@app.route('/result/ios.png', methods=['GET'])
def result():
if os.path.exists('result/ios.png'):
with open('result/ios.png', 'rb') as f:
return f.read()
return ""
@app.route('/original/input.png', methods=['GET'])
def orig():
if os.path.exists('original/input.png'):
with open('original/input.png', 'rb') as f:
return f.read()
return ""
@app.route('/', methods=['POST'])
def upload_img():
# print(request.files)
img = request.files.get('upload_img', None)
with open('uploaded_img.dng', 'wb') as f:
f.write(img.read())
dng2png.convert('./uploaded_img.dng')
new_path = draw_inference.infrence('./uploaded_img.dng', 'ios')
print(new_path)
return redirect('/')