Untitled

mail@pastecode.io avatar
unknown
python
21 days ago
929 B
2
Indexable
Never
	def getProperty(self, png_file_path, node_id, input_key):
		# Open the PNG file
		with Image.open(png_file_path) as img:
			# Extract metadata
			metadata = img.info

		# Look for the custom JSON key in the metadata
		json_data = metadata.get('prompt')
		if json_data is None:
			raise ValueError("No 'prompt' JSON metadata found in the PNG file.")

		# Parse the JSON metadata
		try:
			data = json.loads(json_data)
		except json.JSONDecodeError as e:
			raise ValueError("Invalid JSON data found in the metadata.") from e

		# Search for the node with the given ID
		node_info = data.get(str(node_id))
		if node_info is None:
			raise ValueError(f"Node with ID {node_id} not found.")

		# Extract the input value
		input_value = node_info.get('inputs', {}).get(input_key)
		if input_value is None:
			raise ValueError(f"Input key '{input_key}' not found in node ID {node_id}.")

		print(input_value)
Leave a Comment