mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(nodes): remove dataURL invocation
This commit is contained in:
parent
6945d10297
commit
4ef0e43759
@ -5,8 +5,7 @@ from typing import Literal, Optional
|
||||
|
||||
import numpy
|
||||
from PIL import Image, ImageFilter, ImageOps
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from w3lib.url import parse_data_uri
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..models.image import ImageField, ImageType
|
||||
from .baseinvocation import (
|
||||
@ -118,45 +117,6 @@ class ShowImageInvocation(BaseInvocation):
|
||||
)
|
||||
|
||||
|
||||
class DataURLToImageInvocation(BaseInvocation, PILInvocationConfig):
|
||||
"""Outputs an image from a data URL."""
|
||||
|
||||
type: Literal["dataURL_image"] = "dataURL_image"
|
||||
|
||||
# Inputs
|
||||
dataURL: str = Field(description="The b64 data URL")
|
||||
|
||||
@validator("dataURL")
|
||||
def must_be_valid_image_dataURL(cls, v):
|
||||
try:
|
||||
result = parse_data_uri(v)
|
||||
img = Image.open(io.BytesIO(result.data))
|
||||
img.verify()
|
||||
except Exception:
|
||||
raise ValueError("Invalid image dataURL")
|
||||
return v
|
||||
|
||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||
# TODO: Figure out how to use pydantic validator to also transform into a different type,
|
||||
# bc this is just the same logic as we use to validate the dataURL.
|
||||
result = parse_data_uri(self.dataURL)
|
||||
image = Image.open(io.BytesIO(result.data))
|
||||
|
||||
image_name = context.services.images.create_name(
|
||||
context.graph_execution_state_id, self.id
|
||||
)
|
||||
|
||||
metadata = context.services.metadata.build_metadata(
|
||||
session_id=context.graph_execution_state_id, node=self
|
||||
)
|
||||
|
||||
context.services.images.save(ImageType.RESULT, image_name, image, metadata)
|
||||
|
||||
return build_image_output(
|
||||
image_type=ImageType.RESULT, image_name=image_name, image=image
|
||||
)
|
||||
|
||||
|
||||
class CropImageInvocation(BaseInvocation, PILInvocationConfig):
|
||||
"""Crops an image to a specified box. The box can be outside of the image."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user