How to use the mlpm.response.json_resp function in mlpm

To help you get started, we’ve selected a few mlpm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github autoai-org / AID / components / mlserve / mlpm / handler.py View on Github external
output = []
            for index, each in enumerate(csv_dict):
                each.update(results[index])
                output.append(each)
        if not os.path.isdir(target_folder):
            os.makedirs(target_folder)
        file_identifier = str(uuid.uuid4())
        output_file_path = os.path.join(target_folder,
                                        file_identifier + ".csv")
        head = output[0].keys()
        with open(output_file_path, 'w') as file_obj:
            writer = DictWriter(file_obj, fieldnames=head)
            writer.writeheader()
            for each in output:
                writer.writerow(each)
        return json_resp({'filename': file_identifier + ".csv"}, status=200)
    except Exception as e:
        traceback.print_exc()
        return json_resp({"error": str(e), "code": "500"}, status=500)
github autoai-org / AID / components / mlserve / mlpm / handler.py View on Github external
# make sure the UPLOAD_FOLDER exsits
        if not os.path.isdir(upload_folder):
            os.makedirs(upload_folder)
        file_abs_path = os.path.join(upload_folder, filename)
        uploaded_file.save(file_abs_path)
        data['input_file_path'] = file_abs_path
    try:
        if request_type == "infer":
            results = aidserver.solver.infer(data)
        else:
            raise NotImplementedError
        if 'delete_after_process' in data:
            if str2bool(data['delete_after_process']):
                os.remove(file_abs_path)
        print(results)
        return json_resp(results, status=200)
    except Exception as e:
        traceback.print_exc()
        return json_resp({"error": str(e), "code": "500"}, status=500)
github autoai-org / AID / components / mlserve / mlpm / server.py View on Github external
async def ping():
    return await json_resp({"status": "OK"}, status=200)