-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver1.py
59 lines (44 loc) · 1.64 KB
/
server1.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
52
53
54
55
56
57
58
59
from flask import Flask, jsonify, request, render_template
import os
from flask import flash, request, redirect, url_for
from werkzeug.utils import secure_filename
import numpy as np
import asyncio
import json
from flask import jsonify
import webbrowser
from psutil import process_iter
import http.server
import socketserver
from threading import Thread
import handler
import base64
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
def start():
app = Flask(__name__)
UPLOAD_FOLDER = './'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/', methods=['GET', 'POST'])
def upload_images():
if request.method == 'POST':
print(request)
handled_images = []
pixels = request.form.to_dict(flat=False)['pixels'][0]
bit = base64.b64decode(pixels)
des_b = np.frombuffer(bit, dtype=np.uint8)
answer = handler.get_start(des_b)
response = app.response_class(
response=json.dumps(answer,cls=NumpyEncoder),
status=200,
mimetype='application/json'
)
response.headers['Access-Control-Allow-Origin'] = "*"
return response
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
port_main = 8000
app.run(port=port_main,threaded=False)
start()