22
33import cv2
44import numpy as np
5- from pydantic import AliasChoices , ConfigDict , Field
5+ from pydantic import AliasChoices , ConfigDict , Field , PositiveInt
66
77from inference .core .workflows .execution_engine .entities .base import (
88 OutputDefinition ,
@@ -55,12 +55,11 @@ class ImagePreprocessingManifest(WorkflowBlockManifest):
5555 task_type : Literal ["resize" , "rotate" , "flip" ] = Field (
5656 description = "Preprocessing task to be applied to the image." ,
5757 )
58- width : Union [int , Selector (kind = [INTEGER_KIND ])] = Field ( # type: ignore
58+ width : Union [PositiveInt , Selector (kind = [INTEGER_KIND ])] = Field ( # type: ignore
5959 title = "Width" ,
6060 default = 640 ,
6161 description = "Width of the image to be resized to." ,
6262 examples = [640 , "$inputs.resize_width" ],
63- gt = 0 ,
6463 json_schema_extra = {
6564 "relevant_for" : {
6665 "task_type" : {
@@ -70,12 +69,11 @@ class ImagePreprocessingManifest(WorkflowBlockManifest):
7069 },
7170 },
7271 )
73- height : Union [int , Selector (kind = [INTEGER_KIND ])] = Field ( # type: ignore
72+ height : Union [PositiveInt , Selector (kind = [INTEGER_KIND ])] = Field ( # type: ignore
7473 title = "Height" ,
7574 default = 640 ,
7675 description = "Height of the image to be resized to." ,
7776 examples = [640 , "$inputs.resize_height" ],
78- gt = 0 ,
7977 json_schema_extra = {
8078 "relevant_for" : {
8179 "task_type" : {
@@ -90,8 +88,6 @@ class ImagePreprocessingManifest(WorkflowBlockManifest):
9088 description = "Positive value to rotate clockwise, negative value to rotate counterclockwise" ,
9189 default = 90 ,
9290 examples = [90 , "$inputs.rotation_degrees" ],
93- ge = - 360 ,
94- le = 360 ,
9591 json_schema_extra = {
9692 "relevant_for" : {
9793 "task_type" : {
@@ -101,7 +97,9 @@ class ImagePreprocessingManifest(WorkflowBlockManifest):
10197 }
10298 },
10399 )
104- flip_type : Union [Selector (kind = [STRING_KIND ]), Literal ["vertical" , "horizontal" , "both" ]] = Field ( # type: ignore
100+ flip_type : Union [
101+ Selector (kind = [STRING_KIND ]), Literal ["vertical" , "horizontal" , "both" ]
102+ ] = Field ( # type: ignore
105103 title = "Flip Type" ,
106104 description = "Type of flip to be applied to the image." ,
107105 default = "vertical" ,
@@ -150,10 +148,24 @@ def run(
150148 response_image = None
151149
152150 if task_type == "resize" :
151+ if width is not None and width <= 0 :
152+ raise ValueError ("Width must be greater than 0" )
153+ if height is not None and height <= 0 :
154+ raise ValueError ("Height must be greater than 0" )
153155 response_image = apply_resize_image (image .numpy_image , width , height )
154156 elif task_type == "rotate" :
157+ if rotation_degrees is not None and not (- 360 <= rotation_degrees <= 360 ):
158+ raise ValueError ("Rotation degrees must be between -360 and 360" )
155159 response_image = apply_rotate_image (image .numpy_image , rotation_degrees )
156160 elif task_type == "flip" :
161+ if flip_type is not None and flip_type not in [
162+ "vertical" ,
163+ "horizontal" ,
164+ "both" ,
165+ ]:
166+ raise ValueError (
167+ "Flip type must be 'vertical', 'horizontal', or 'both'"
168+ )
157169 response_image = apply_flip_image (image .numpy_image , flip_type )
158170 else :
159171 raise ValueError (f"Invalid task type: { task_type } " )
0 commit comments