-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_server.py
More file actions
34 lines (23 loc) · 892 Bytes
/
file_server.py
File metadata and controls
34 lines (23 loc) · 892 Bytes
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
from flask import Flask, request, jsonify
from PIL import Image
import time
app = Flask(__name__)
@app.route("/im_size", methods=["POST"])
def process_image():
start = time.time()
print('request size',"{0:.2f}".format(int(request.headers.get('Content-Length'))/1024) +'KB')
file = request.files['image']
print('file time:',time.time()-start)
start2=time.time()
# Read the image via file.stream
img = Image.open(file.stream)
payload = request.form.to_dict()
print('payload:',payload)
#time.sleep(2) #to mimick inference
print('Imread+payload time:',time.time()-start2)
#my_img = {'image': open('1.jpg', 'rb')}
my_img=''
print('process time:',time.time()-start)
return jsonify({'msg': 'success', 'size': [img.width, img.height], 'img1':my_img})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)