base on falcon framework, some useful tools post image, numpy and json file or parameters
pip install git+https://github.com/aidings/fcserver.git
-
server(deploy model)
from fcserver import FalconServer, App from PIL import Image from wsgiref.simple_server import make_server class Server(FalconServer): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) print('My server model loadding...') def on_post(self, req, resp): # pudb.set_trace() # print(req.params) # img_a = self.decode_image(req, 'aimg') img_a = self.decode_numpy(req, 'aimg') self.save_data('aimg.png', img_a) img_b = self.decode_image(req, 'bimg') self.save_data('bimg.png', img_b) resp.body = json.dumps('aimg': 'is a numpy', 'bimg': 'is a image') s = Server() app = App() app.add_route('/ding', s) if __name__ == '__main__': with make_server('127.0.0.1', 8088, app) as httpd: httpd.serve_forever()
-
client(send data to server)
import cv2 import json from fcserver import FalconClient if __name__ == '__main__': c = FalconClient('https://127.0.0.1:8088/ding', None) c.push_file(cv2.imread('./demo.png'), 'aimg', is_img=False) c.push_file('./demo2.png', 'bimg') # print(files) c.send(query={'test': [1, 2, 3]}, data={'a': [4, 5, 6]})
-
gunicorn(deploy the server)
gunicorn --workers=2 --bind 0.0.0.0:8088 demo:app
-
uwsgi(deploy the server)
uwsgi --ini uwsgi.ini