mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(nodes): remove LibraryGraphs
The workflow library supersedes this unused feature.
This commit is contained in:
parent
1a56f5aaf9
commit
dcb4ee47d5
@ -1,92 +0,0 @@
|
|||||||
from invokeai.app.services.item_storage.item_storage_base import ItemStorageABC
|
|
||||||
|
|
||||||
from ...invocations.compel import CompelInvocation
|
|
||||||
from ...invocations.image import ImageNSFWBlurInvocation
|
|
||||||
from ...invocations.latent import DenoiseLatentsInvocation, LatentsToImageInvocation
|
|
||||||
from ...invocations.noise import NoiseInvocation
|
|
||||||
from ...invocations.primitives import IntegerInvocation
|
|
||||||
from .graph import Edge, EdgeConnection, ExposedNodeInput, ExposedNodeOutput, Graph, LibraryGraph
|
|
||||||
|
|
||||||
default_text_to_image_graph_id = "539b2af5-2b4d-4d8c-8071-e54a3255fc74"
|
|
||||||
|
|
||||||
|
|
||||||
def create_text_to_image() -> LibraryGraph:
|
|
||||||
graph = Graph(
|
|
||||||
nodes={
|
|
||||||
"width": IntegerInvocation(id="width", value=512),
|
|
||||||
"height": IntegerInvocation(id="height", value=512),
|
|
||||||
"seed": IntegerInvocation(id="seed", value=-1),
|
|
||||||
"3": NoiseInvocation(id="3"),
|
|
||||||
"4": CompelInvocation(id="4"),
|
|
||||||
"5": CompelInvocation(id="5"),
|
|
||||||
"6": DenoiseLatentsInvocation(id="6"),
|
|
||||||
"7": LatentsToImageInvocation(id="7"),
|
|
||||||
"8": ImageNSFWBlurInvocation(id="8"),
|
|
||||||
},
|
|
||||||
edges=[
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="width", field="value"),
|
|
||||||
destination=EdgeConnection(node_id="3", field="width"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="height", field="value"),
|
|
||||||
destination=EdgeConnection(node_id="3", field="height"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="seed", field="value"),
|
|
||||||
destination=EdgeConnection(node_id="3", field="seed"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="3", field="noise"),
|
|
||||||
destination=EdgeConnection(node_id="6", field="noise"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="6", field="latents"),
|
|
||||||
destination=EdgeConnection(node_id="7", field="latents"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="4", field="conditioning"),
|
|
||||||
destination=EdgeConnection(node_id="6", field="positive_conditioning"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="5", field="conditioning"),
|
|
||||||
destination=EdgeConnection(node_id="6", field="negative_conditioning"),
|
|
||||||
),
|
|
||||||
Edge(
|
|
||||||
source=EdgeConnection(node_id="7", field="image"),
|
|
||||||
destination=EdgeConnection(node_id="8", field="image"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
return LibraryGraph(
|
|
||||||
id=default_text_to_image_graph_id,
|
|
||||||
name="t2i",
|
|
||||||
description="Converts text to an image",
|
|
||||||
graph=graph,
|
|
||||||
exposed_inputs=[
|
|
||||||
ExposedNodeInput(node_path="4", field="prompt", alias="positive_prompt"),
|
|
||||||
ExposedNodeInput(node_path="5", field="prompt", alias="negative_prompt"),
|
|
||||||
ExposedNodeInput(node_path="width", field="value", alias="width"),
|
|
||||||
ExposedNodeInput(node_path="height", field="value", alias="height"),
|
|
||||||
ExposedNodeInput(node_path="seed", field="value", alias="seed"),
|
|
||||||
],
|
|
||||||
exposed_outputs=[ExposedNodeOutput(node_path="8", field="image", alias="image")],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def create_system_graphs(graph_library: ItemStorageABC[LibraryGraph]) -> list[LibraryGraph]:
|
|
||||||
"""Creates the default system graphs, or adds new versions if the old ones don't match"""
|
|
||||||
|
|
||||||
# TODO: Uncomment this when we are ready to fix this up to prevent breaking changes
|
|
||||||
graphs: list[LibraryGraph] = []
|
|
||||||
|
|
||||||
text_to_image = graph_library.get(default_text_to_image_graph_id)
|
|
||||||
|
|
||||||
# TODO: Check if the graph is the same as the default one, and if not, update it
|
|
||||||
# if text_to_image is None:
|
|
||||||
text_to_image = create_text_to_image()
|
|
||||||
graph_library.set(text_to_image)
|
|
||||||
|
|
||||||
graphs.append(text_to_image)
|
|
||||||
|
|
||||||
return graphs
|
|
@ -10,7 +10,6 @@ from pydantic import (
|
|||||||
ConfigDict,
|
ConfigDict,
|
||||||
GetJsonSchemaHandler,
|
GetJsonSchemaHandler,
|
||||||
field_validator,
|
field_validator,
|
||||||
model_validator,
|
|
||||||
)
|
)
|
||||||
from pydantic.fields import Field
|
from pydantic.fields import Field
|
||||||
from pydantic.json_schema import JsonSchemaValue
|
from pydantic.json_schema import JsonSchemaValue
|
||||||
@ -1146,58 +1145,3 @@ class GraphExecutionState(BaseModel):
|
|||||||
f"Destination node {edge.destination.node_id} has already been prepared or executed and cannot have a source edge deleted"
|
f"Destination node {edge.destination.node_id} has already been prepared or executed and cannot have a source edge deleted"
|
||||||
)
|
)
|
||||||
self.graph.delete_edge(edge)
|
self.graph.delete_edge(edge)
|
||||||
|
|
||||||
|
|
||||||
class ExposedNodeInput(BaseModel):
|
|
||||||
node_path: str = Field(description="The node path to the node with the input")
|
|
||||||
field: str = Field(description="The field name of the input")
|
|
||||||
alias: str = Field(description="The alias of the input")
|
|
||||||
|
|
||||||
|
|
||||||
class ExposedNodeOutput(BaseModel):
|
|
||||||
node_path: str = Field(description="The node path to the node with the output")
|
|
||||||
field: str = Field(description="The field name of the output")
|
|
||||||
alias: str = Field(description="The alias of the output")
|
|
||||||
|
|
||||||
|
|
||||||
class LibraryGraph(BaseModel):
|
|
||||||
id: str = Field(description="The unique identifier for this library graph", default_factory=uuid_string)
|
|
||||||
graph: Graph = Field(description="The graph")
|
|
||||||
name: str = Field(description="The name of the graph")
|
|
||||||
description: str = Field(description="The description of the graph")
|
|
||||||
exposed_inputs: list[ExposedNodeInput] = Field(description="The inputs exposed by this graph", default_factory=list)
|
|
||||||
exposed_outputs: list[ExposedNodeOutput] = Field(
|
|
||||||
description="The outputs exposed by this graph", default_factory=list
|
|
||||||
)
|
|
||||||
|
|
||||||
@field_validator("exposed_inputs", "exposed_outputs")
|
|
||||||
def validate_exposed_aliases(cls, v: list[Union[ExposedNodeInput, ExposedNodeOutput]]):
|
|
||||||
if len(v) != len({i.alias for i in v}):
|
|
||||||
raise ValueError("Duplicate exposed alias")
|
|
||||||
return v
|
|
||||||
|
|
||||||
@model_validator(mode="after")
|
|
||||||
def validate_exposed_nodes(cls, values):
|
|
||||||
graph = values.graph
|
|
||||||
|
|
||||||
# Validate exposed inputs
|
|
||||||
for exposed_input in values.exposed_inputs:
|
|
||||||
if not graph.has_node(exposed_input.node_path):
|
|
||||||
raise ValueError(f"Exposed input node {exposed_input.node_path} does not exist")
|
|
||||||
node = graph.get_node(exposed_input.node_path)
|
|
||||||
if get_input_field(node, exposed_input.field) is None:
|
|
||||||
raise ValueError(
|
|
||||||
f"Exposed input field {exposed_input.field} does not exist on node {exposed_input.node_path}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Validate exposed outputs
|
|
||||||
for exposed_output in values.exposed_outputs:
|
|
||||||
if not graph.has_node(exposed_output.node_path):
|
|
||||||
raise ValueError(f"Exposed output node {exposed_output.node_path} does not exist")
|
|
||||||
node = graph.get_node(exposed_output.node_path)
|
|
||||||
if get_output_field(node, exposed_output.field) is None:
|
|
||||||
raise ValueError(
|
|
||||||
f"Exposed output field {exposed_output.field} does not exist on node {exposed_output.node_path}"
|
|
||||||
)
|
|
||||||
|
|
||||||
return values
|
|
||||||
|
Loading…
Reference in New Issue
Block a user