Commit d3ec98f4 authored by Bucky Lee's avatar Bucky Lee
Browse files

feat: update

parent 1ac5ec90
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -33,17 +33,19 @@ def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


@app.route('/upload', methods=['GET', 'POST'])
@app.route('/upload/<model_name>', methods=['GET', 'POST'])
def upload_file(model_name):
    file = request.files['file']
    print(datetime.datetime.now(), file.filename)
    msg = ''
    if file and allowed_file(file.filename):
        src_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
        file.save(src_path)
        # shutil.copy(src_path, './tmp/ct')
        image_path = os.path.join('data/unprocessed', file.filename)
        if core.main.process(image_path, model_name):
        shutil.copy(src_path, 'data/processed')
        # msg = core.main.process(src_path, model_name)
        # if msg == 'Success':
        return 'Success!'
    app.logger.info("Failed to deal with image!\n", msg)
    return 'Failed!'


+13 −9
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from core.predict import predict
from core.process import preprocess
from PIL import Image
import cv2
import traceback


def process(file_path, model_name):
@@ -10,7 +11,7 @@ def process(file_path, model_name):
    :param file_path: the path of cataract fundus image
    :param model_name: the model you want to use
    """
    # TODO: fill this
    try: 
        image = Image.open(file_path)
        image_name = file_path.split('/')[-1].split('.')[0]
        processed_image = preprocess(image)
@@ -18,7 +19,10 @@ def process(file_path, model_name):
        restored_image = Image.fromarray(restored_image)
        save_path = str(f'./data/{image_name}.png')
        restored_image.save(save_path)
    return 'Success'
        return "Success"
    except Exception as e:
        return traceback.format_exception()
    


if __name__ == '__main__':
+44.9 KiB
Loading image diff...
Loading