From 0d86434eb3773c6ff5af3bfcd63c5b1bfd9ebff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C4=99czek?= Date: Tue, 29 Oct 2024 16:33:31 +0100 Subject: [PATCH 1/2] Apply fixes to allow for binary attachments --- .../aggregating_objects_passing_data.py | 7 +++++++ .../formatters/property_definition/v1.py | 16 +++------------- .../core_steps/sinks/email_notification/v1.py | 8 ++++++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/development/workflows_examples/video_analysis/aggregating_objects_passing_data.py b/development/workflows_examples/video_analysis/aggregating_objects_passing_data.py index 427ef9999..28027892f 100644 --- a/development/workflows_examples/video_analysis/aggregating_objects_passing_data.py +++ b/development/workflows_examples/video_analysis/aggregating_objects_passing_data.py @@ -80,6 +80,12 @@ "people_passed": "$steps.data_aggregator.people_passed_values_difference" } }, + { + "type": "roboflow_core/property_definition@v1", + "name": "image_as_jpeg", + "operations": [{"type": "ConvertImageToJPEG"}], + "data": "$steps.line_counter_visualization.image", + }, { "type": "roboflow_core/email_notification@v1", "name": "email_notifier", @@ -91,6 +97,7 @@ }, "attachments": { "report.csv": "$steps.csv_formatter.csv_content", + "image.jpeg": "$steps.image_as_jpeg.output", }, "receiver_email": "$inputs.email", "smtp_server": "smtp.gmail.com", diff --git a/inference/core/workflows/core_steps/formatters/property_definition/v1.py b/inference/core/workflows/core_steps/formatters/property_definition/v1.py index a5669a220..8fb0bc05f 100644 --- a/inference/core/workflows/core_steps/formatters/property_definition/v1.py +++ b/inference/core/workflows/core_steps/formatters/property_definition/v1.py @@ -1,4 +1,4 @@ -from typing import Any, List, Literal, Optional, Type +from typing import Any, List, Literal, Optional, Type, Union from pydantic import ConfigDict, Field @@ -10,11 +10,8 @@ ) from inference.core.workflows.execution_engine.entities.base import OutputDefinition from inference.core.workflows.execution_engine.entities.types import ( - CLASSIFICATION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, - OBJECT_DETECTION_PREDICTION_KIND, StepOutputSelector, + WorkflowImageSelector, ) from inference.core.workflows.prototypes.block import ( BlockResult, @@ -60,14 +57,7 @@ class BlockManifest(WorkflowBlockManifest): "PropertyDefinition", "PropertyExtraction", ] - data: StepOutputSelector( - kind=[ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, - CLASSIFICATION_PREDICTION_KIND, - ] - ) = Field( + data: Union[WorkflowImageSelector, StepOutputSelector()] = Field( description="Reference data to extract property from", examples=["$steps.my_step.predictions"], ) diff --git a/inference/core/workflows/core_steps/sinks/email_notification/v1.py b/inference/core/workflows/core_steps/sinks/email_notification/v1.py index 954b2fc0f..f4d9ed82a 100644 --- a/inference/core/workflows/core_steps/sinks/email_notification/v1.py +++ b/inference/core/workflows/core_steps/sinks/email_notification/v1.py @@ -30,6 +30,7 @@ STRING_KIND, StepOutputSelector, WorkflowParameterSelector, + BYTES_KIND, ) from inference.core.workflows.prototypes.block import ( BlockResult, @@ -235,7 +236,7 @@ class BlockManifest(WorkflowBlockManifest): ], default_factory=dict, ) - attachments: Dict[str, StepOutputSelector(kind=[STRING_KIND])] = Field( + attachments: Dict[str, StepOutputSelector(kind=[STRING_KIND, BYTES_KIND])] = Field( description="Attachments", default_factory=dict, examples=[{"report.cvs": "$steps.csv_formatter.csv_content"}], @@ -507,7 +508,10 @@ def _send_email_using_smtp_server( e_mail_message.attach(MIMEText(message, "plain")) for attachment_name, attachment_content in attachments.items(): part = MIMEBase("application", "octet-stream") - part.set_payload(attachment_content.encode("utf-8")) + binary_payload = attachment_content + if not isinstance(binary_payload, bytes): + binary_payload = binary_payload.encode("utf-8") + part.set_payload(binary_payload) encoders.encode_base64(part) part.add_header( "Content-Disposition", From 96220a64a65670bf303a0bf6205f159f8349390e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C4=99czek?= Date: Tue, 29 Oct 2024 16:36:50 +0100 Subject: [PATCH 2/2] Make linters happpy --- .../core/workflows/core_steps/sinks/email_notification/v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference/core/workflows/core_steps/sinks/email_notification/v1.py b/inference/core/workflows/core_steps/sinks/email_notification/v1.py index f4d9ed82a..6c5f7def5 100644 --- a/inference/core/workflows/core_steps/sinks/email_notification/v1.py +++ b/inference/core/workflows/core_steps/sinks/email_notification/v1.py @@ -25,12 +25,12 @@ from inference.core.workflows.execution_engine.entities.base import OutputDefinition from inference.core.workflows.execution_engine.entities.types import ( BOOLEAN_KIND, + BYTES_KIND, INTEGER_KIND, LIST_OF_VALUES_KIND, STRING_KIND, StepOutputSelector, WorkflowParameterSelector, - BYTES_KIND, ) from inference.core.workflows.prototypes.block import ( BlockResult,