Beispiel #1
0
def prediction():
    image_id = request.json.get('img_id')
    question = request.json.get('question')

    img = Image.get(image_id)

    if img is None:
        kwargs = {'status': 'error', 'message': 'invalid image id'}
        response = jsonify(kwargs)
        response.status_code = 400
    else:
        filepath = os.path.join(Config.UPLOAD_DIR, img.filename)
        path = os.path.join(Config.STATIC_DIR, f'{filepath}')
        pred, fig_id = asyncio.run(run_model(path, question))

        if fig_id > 0:
            #fig = WeightFigure.get(fig_id)
            #figfile = fig.filename
            #figpath = os.path.join(Config.FIG_DIR, figfile)
            pass

        kwargs = {'status': 'success'}
        data = {'prediction': pred}
        response = jsonify(data=data, **kwargs)
        response.status_code = 200

    return response
Beispiel #2
0
def extract_qa_by_request_log(req_id):

    log = RequestLog.get(req_id)
    kwargs = {
        'status': 'success',
        'task': 'read-only',
        'type': 'request log',
    }

    data = {
        'request_id': req_id,
        'question': Question.get(log.question_id).question,
        'prediction': log.score.prediction,
        'image': Image.get(log.image_id).filename,
        'figure': WeightFigure.get(log.fig_id).filename,
    }

    response = jsonify(data=data, **kwargs)
    response.status_code = 200
    return response