|
39 | 39 | VAEField,
|
40 | 40 | VAEOutput,
|
41 | 41 | )
|
42 |
| -from invokeai.app.invocations.primitives import BooleanOutput, FloatOutput, IntegerOutput, LatentsOutput, StringOutput |
| 42 | +from invokeai.app.invocations.primitives import ( |
| 43 | + BooleanCollectionOutput, |
| 44 | + BooleanOutput, |
| 45 | + FloatCollectionOutput, |
| 46 | + FloatOutput, |
| 47 | + IntegerCollectionOutput, |
| 48 | + IntegerOutput, |
| 49 | + LatentsOutput, |
| 50 | + StringCollectionOutput, |
| 51 | + StringOutput, |
| 52 | +) |
43 | 53 | from invokeai.app.invocations.scheduler import SchedulerOutput
|
44 | 54 | from invokeai.app.invocations.t2i_adapter import T2IAdapterField, T2IAdapterInvocation
|
45 | 55 | from invokeai.app.services.shared.invocation_context import InvocationContext
|
@@ -1162,3 +1172,133 @@ def invoke(self, context: InvocationContext) -> MDT2IAdapterListOutput:
|
1162 | 1172 | adapters = append_list(T2IAdapterField, i.t2i_adapter, adapters)
|
1163 | 1173 |
|
1164 | 1174 | return MDT2IAdapterListOutput(t2i_adapter_list=adapters)
|
| 1175 | + |
| 1176 | + |
| 1177 | +@invocation( |
| 1178 | + "metadata_to_string_collection", |
| 1179 | + title="Metadata To String Collection", |
| 1180 | + tags=["metadata"], |
| 1181 | + category="metadata", |
| 1182 | + version="1.0.0", |
| 1183 | + classification=Classification.Beta, |
| 1184 | +) |
| 1185 | +class MetadataToStringCollectionInvocation(BaseInvocation, WithMetadata): |
| 1186 | + """Extracts a string collection value of a label from metadata""" |
| 1187 | + |
| 1188 | + label: CORE_LABELS_STRING = InputField( |
| 1189 | + default=CUSTOM_LABEL, |
| 1190 | + description=FieldDescriptions.metadata_item_label, |
| 1191 | + input=Input.Direct, |
| 1192 | + ) |
| 1193 | + custom_label: Optional[str] = InputField( |
| 1194 | + default=None, |
| 1195 | + description=FieldDescriptions.metadata_item_label, |
| 1196 | + input=Input.Direct, |
| 1197 | + ) |
| 1198 | + default_value: list[str] = InputField( |
| 1199 | + description="The default string collection to use if not found in the metadata" |
| 1200 | + ) |
| 1201 | + |
| 1202 | + _validate_custom_label = model_validator(mode="after")(validate_custom_label) |
| 1203 | + |
| 1204 | + def invoke(self, context: InvocationContext) -> StringCollectionOutput: |
| 1205 | + data: Dict[str, Any] = {} if self.metadata is None else self.metadata.root |
| 1206 | + output = data.get(str(self.custom_label if self.label == CUSTOM_LABEL else self.label), self.default_value) |
| 1207 | + |
| 1208 | + return StringCollectionOutput(collection=output) |
| 1209 | + |
| 1210 | + |
| 1211 | +@invocation( |
| 1212 | + "metadata_to_integer_collection", |
| 1213 | + title="Metadata To Integer Collection", |
| 1214 | + tags=["metadata"], |
| 1215 | + category="metadata", |
| 1216 | + version="1.0.0", |
| 1217 | + classification=Classification.Beta, |
| 1218 | +) |
| 1219 | +class MetadataToIntegerCollectionInvocation(BaseInvocation, WithMetadata): |
| 1220 | + """Extracts an integer value Collection of a label from metadata""" |
| 1221 | + |
| 1222 | + label: CORE_LABELS_INTEGER = InputField( |
| 1223 | + default=CUSTOM_LABEL, |
| 1224 | + description=FieldDescriptions.metadata_item_label, |
| 1225 | + input=Input.Direct, |
| 1226 | + ) |
| 1227 | + custom_label: Optional[str] = InputField( |
| 1228 | + default=None, |
| 1229 | + description=FieldDescriptions.metadata_item_label, |
| 1230 | + input=Input.Direct, |
| 1231 | + ) |
| 1232 | + default_value: list[int] = InputField(description="The default integer to use if not found in the metadata") |
| 1233 | + |
| 1234 | + _validate_custom_label = model_validator(mode="after")(validate_custom_label) |
| 1235 | + |
| 1236 | + def invoke(self, context: InvocationContext) -> IntegerCollectionOutput: |
| 1237 | + data: Dict[str, Any] = {} if self.metadata is None else self.metadata.root |
| 1238 | + output = data.get(str(self.custom_label if self.label == CUSTOM_LABEL else self.label), self.default_value) |
| 1239 | + |
| 1240 | + return IntegerCollectionOutput(collection=output) |
| 1241 | + |
| 1242 | + |
| 1243 | +@invocation( |
| 1244 | + "metadata_to_float_collection", |
| 1245 | + title="Metadata To Float Collection", |
| 1246 | + tags=["metadata"], |
| 1247 | + category="metadata", |
| 1248 | + version="1.0.0", |
| 1249 | + classification=Classification.Beta, |
| 1250 | +) |
| 1251 | +class MetadataToFloatCollectionInvocation(BaseInvocation, WithMetadata): |
| 1252 | + """Extracts a Float value Collection of a label from metadata""" |
| 1253 | + |
| 1254 | + label: CORE_LABELS_FLOAT = InputField( |
| 1255 | + default=CUSTOM_LABEL, |
| 1256 | + description=FieldDescriptions.metadata_item_label, |
| 1257 | + input=Input.Direct, |
| 1258 | + ) |
| 1259 | + custom_label: Optional[str] = InputField( |
| 1260 | + default=None, |
| 1261 | + description=FieldDescriptions.metadata_item_label, |
| 1262 | + input=Input.Direct, |
| 1263 | + ) |
| 1264 | + default_value: list[float] = InputField(description="The default float to use if not found in the metadata") |
| 1265 | + |
| 1266 | + _validate_custom_label = model_validator(mode="after")(validate_custom_label) |
| 1267 | + |
| 1268 | + def invoke(self, context: InvocationContext) -> FloatCollectionOutput: |
| 1269 | + data: Dict[str, Any] = {} if self.metadata is None else self.metadata.root |
| 1270 | + output = data.get(str(self.custom_label if self.label == CUSTOM_LABEL else self.label), self.default_value) |
| 1271 | + |
| 1272 | + return FloatCollectionOutput(collection=output) |
| 1273 | + |
| 1274 | + |
| 1275 | +@invocation( |
| 1276 | + "metadata_to_bool_collection", |
| 1277 | + title="Metadata To Bool Collection", |
| 1278 | + tags=["metadata"], |
| 1279 | + category="metadata", |
| 1280 | + version="1.0.0", |
| 1281 | + classification=Classification.Beta, |
| 1282 | +) |
| 1283 | +class MetadataToBoolCollectionInvocation(BaseInvocation, WithMetadata): |
| 1284 | + """Extracts a Boolean value Collection of a label from metadata""" |
| 1285 | + |
| 1286 | + label: CORE_LABELS_BOOL = InputField( |
| 1287 | + default=CUSTOM_LABEL, |
| 1288 | + description=FieldDescriptions.metadata_item_label, |
| 1289 | + input=Input.Direct, |
| 1290 | + ) |
| 1291 | + custom_label: Optional[str] = InputField( |
| 1292 | + default=None, |
| 1293 | + description=FieldDescriptions.metadata_item_label, |
| 1294 | + input=Input.Direct, |
| 1295 | + ) |
| 1296 | + default_value: list[bool] = InputField(description="The default bool to use if not found in the metadata") |
| 1297 | + |
| 1298 | + _validate_custom_label = model_validator(mode="after")(validate_custom_label) |
| 1299 | + |
| 1300 | + def invoke(self, context: InvocationContext) -> BooleanCollectionOutput: |
| 1301 | + data: Dict[str, Any] = {} if self.metadata is None else self.metadata.root |
| 1302 | + output = data.get(str(self.custom_label if self.label == CUSTOM_LABEL else self.label), self.default_value) |
| 1303 | + |
| 1304 | + return BooleanCollectionOutput(collection=output) |
0 commit comments