From 9282c20b6356102e39b96d74a9783feee44910c0 Mon Sep 17 00:00:00 2001 From: sumn2u Date: Sun, 16 Jun 2024 19:13:46 -0500 Subject: [PATCH] added color map to the response of configuration download --- README.md | 14 +++++++++++++- server/app.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9db7bdc..b566306 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,19 @@ Sample of annotated image along with its mask and settings is show below. 0.6981424148606811 ] } - ] + ], + "color-map":{ + "Orange":[ + 244, + 67, + 54 + ], + "Apple":[ + 33, + 150, + 243 + ] + } } ] } diff --git a/server/app.py b/server/app.py index 718ca5a..8b19a1e 100644 --- a/server/app.py +++ b/server/app.py @@ -127,11 +127,15 @@ def save_active_image_info(): return jsonify({"status": "error", "message": "An error occurred while processing the request"}), 500 -def create_json_response(image_name): +def create_json_response(image_name, color_map=None): imagesName = [] base_url = request.host_url + 'uploads/' # Initialize the main dictionary for storing image information main_dict = {'image-name': image_name, 'regions': []} + + if color_map: + main_dict['color-map'] = color_map + added_region_ids = set() # Set to track added region IDs for (root, dirs, files) in os.walk(path): @@ -240,10 +244,12 @@ def download_configuration(): data = request.get_json() # Ensure the expected structure of the JSON data image_name = data.get('image_name') + color_map = data.get("colorMap", None) + if not image_name: raise ValueError("Invalid JSON data format: 'image_name' not found.") - json_bytes, download_filename = create_json_response(image_name) + json_bytes, download_filename = create_json_response(image_name, color_map) return send_file(json_bytes, mimetype='application/json', as_attachment=True, download_name=download_filename)