Skip to content

Commit

Permalink
Merge pull request #758 from roboflow/fix/property_definition_accepti…
Browse files Browse the repository at this point in the history
…ng_broader_inputs

Apply fixes to allow for binary attachments in e-mail block
  • Loading branch information
PawelPeczek-Roboflow authored Nov 1, 2024
2 parents fefd822 + aef8e63 commit 1ad728e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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,
Expand Down Expand Up @@ -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"}],
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1ad728e

Please sign in to comment.