-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
38 lines (32 loc) · 1.09 KB
/
server.py
File metadata and controls
38 lines (32 loc) · 1.09 KB
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
from flask import *
from itsdangerous import base64_decode
from PIL import Image
from io import BytesIO
import threading
app = Flask(__name__)
lock = threading.Lock()
@app.route("/upload/mask", methods = ["POST"])
def uploadMask():
data = request.get_json()
name = data['name']
base64_mask = data['mask']
bytes_mask = base64_decode(base64_mask)
mask = Image.open(BytesIO(bytes_mask))
mask.save('./static/resource/masks/'+name)
return make_response()
@app.route("/upload/artificialMask", methods = ["POST"])
def uploadArtiMask():
data = request.get_json()
name = data['name']
base64_mask = data['mask']
bytes_mask = base64_decode(base64_mask)
mask = Image.open(BytesIO(bytes_mask))
mask.save('./static/resource/masks_artificial/'+name)
return make_response()
@app.route("/download/colorTransTable", methods = ["POST"])
def downloadColorTransTable():
with open('./static/resource/colorTransTable.json','r',encoding='utf-8') as fp:
file_content = fp.read()
return make_response(file_content)
if __name__ == '__main__':
app.run()