Skip to content

Commit

Permalink
recovered the app
Browse files Browse the repository at this point in the history
  • Loading branch information
lext committed Nov 27, 2019
1 parent 0faf132 commit 8c4d2e8
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions ouludeepknee/inference/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
import argparse
import base64
import glob
import logging
import os

import cv2
from flask import Flask, request
from flask import jsonify, make_response
from gevent.pywsgi import WSGIServer
import socketio
import eventlet

import logging
from ouludeepknee.inference.pipeline import KneeNetEnsemble

app = Flask(__name__)
# Wrap Flask application with socketio's middleware
sio = socketio.Server(ping_timeout=120, ping_interval=120)


def numpy2base64(img):
_, buffer = cv2.imencode('.png', cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
return 'data:image/png;base64,' + base64.b64encode(buffer).decode('ascii')


app = Flask(__name__)


def call_pipeline(dicom_raw, landmarks=None):
# Localization of ROIs and their conversion into 8-bit 140x140mm images
res_bilateral = net.predict_draw_bilateral(dicom_raw, args.sizemm, args.pad,
Expand All @@ -49,6 +46,7 @@ def call_pipeline(dicom_raw, landmarks=None):
'msg': 'Finished!'}
return response


# curl -F dicom=@01 -X POST http://127.0.0.1:5001/deepknee/predict/bilateral
@app.route('/deepknee/predict/bilateral', methods=['POST'])
def analyze_knee():
Expand All @@ -64,18 +62,6 @@ def analyze_knee():
return make_response(response, 200)


@sio.on('dicom_submission', namespace='/deepknee/sockets')
def on_dicom_submission(sid, data):
sio.emit('dicom_received', dict(), room=sid, namespace='/deepknee/sockets')
logger.info(f'Sent a message back to {sid}')
sio.sleep(0)

tmp = data['file_blob'].split(',', 1)[1]
response = call_pipeline(base64.b64decode(tmp))
# Send out the results
sio.emit('dicom_processed', response, room=sid, namespace='/deepknee/sockets')


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--snapshots_path', default='')
Expand All @@ -96,12 +82,8 @@ def on_dicom_submission(sid, data):
mean_std_path=os.path.join(args.snapshots_path, 'mean_std.npy'),
device=args.device)

app = socketio.WSGIApp(sio, app, socketio_path='/deepknee/sockets/socket.io')

if args.deploy:
# Deploy as an eventlet WSGI server
eventlet.wsgi.server(eventlet.listen((args.deploy_addr, args.port)), app, log=logger)
# http_server = WSGIServer((args.deploy_addr, 5001), app, log=logger)
# http_server.serve_forever()
http_server = WSGIServer((args.deploy_addr, args.port), app, log=logger)
http_server.serve_forever()
else:
app.run(host=args.deploy_addr, port=args.port, debug=True)

0 comments on commit 8c4d2e8

Please sign in to comment.