mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-06 14:07:09 +08:00
Add Camera Concepts (luma_concepts) to Luma Video nodes (#33)
Co-authored-by: Robin Huang <robin.j.huang@gmail.com>
This commit is contained in:
parent
4a67cdb23a
commit
557328a9ee
@ -12,6 +12,7 @@ from pydantic import BaseModel, Field, confloat
|
|||||||
|
|
||||||
class LumaIO:
|
class LumaIO:
|
||||||
LUMA_REF = "LUMA_REF"
|
LUMA_REF = "LUMA_REF"
|
||||||
|
LUMA_CONCEPTS = "LUMA_CONCEPTS"
|
||||||
|
|
||||||
|
|
||||||
class LumaReference:
|
class LumaReference:
|
||||||
@ -47,6 +48,89 @@ class LumaReferenceChain:
|
|||||||
return c
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
class LumaConcept:
|
||||||
|
def __init__(self, key: str):
|
||||||
|
self.key = key
|
||||||
|
|
||||||
|
|
||||||
|
class LumaConceptChain:
|
||||||
|
def __init__(self, str_list: list[str] = None):
|
||||||
|
self.concepts: list[LumaConcept] = []
|
||||||
|
if str_list is not None:
|
||||||
|
for c in str_list:
|
||||||
|
if c != "None":
|
||||||
|
self.add(LumaConcept(key=c))
|
||||||
|
|
||||||
|
def add(self, concept: LumaConcept):
|
||||||
|
self.concepts.append(concept)
|
||||||
|
|
||||||
|
def create_api_model(self):
|
||||||
|
if len(self.concepts) == 0:
|
||||||
|
return None
|
||||||
|
api_concepts: list[LumaConceptObject] = []
|
||||||
|
for concept in self.concepts:
|
||||||
|
if concept.key == "None":
|
||||||
|
continue
|
||||||
|
api_concepts.append(LumaConceptObject(key=concept.key))
|
||||||
|
if len(api_concepts) == 0:
|
||||||
|
return None
|
||||||
|
return api_concepts
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
c = LumaConceptChain()
|
||||||
|
for concept in self.concepts:
|
||||||
|
c.add(concept)
|
||||||
|
return c
|
||||||
|
|
||||||
|
def clone_and_merge(self, other: LumaConceptChain):
|
||||||
|
c = self.clone()
|
||||||
|
for concept in other.concepts:
|
||||||
|
c.add(concept)
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
def get_luma_concepts(include_none=False):
|
||||||
|
concepts = []
|
||||||
|
if include_none:
|
||||||
|
concepts.append("None")
|
||||||
|
return concepts + [
|
||||||
|
"truck_left",
|
||||||
|
"pan_right",
|
||||||
|
"pedestal_down",
|
||||||
|
"low_angle",
|
||||||
|
"pedestal_up",
|
||||||
|
"selfie",
|
||||||
|
"pan_left",
|
||||||
|
"roll_right",
|
||||||
|
"zoom_in",
|
||||||
|
"over_the_shoulder",
|
||||||
|
"orbit_right",
|
||||||
|
"orbit_left",
|
||||||
|
"static",
|
||||||
|
"tiny_planet",
|
||||||
|
"high_angle",
|
||||||
|
"bolt_cam",
|
||||||
|
"dolly_zoom",
|
||||||
|
"overhead",
|
||||||
|
"zoom_out",
|
||||||
|
"handheld",
|
||||||
|
"roll_left",
|
||||||
|
"pov",
|
||||||
|
"aerial_drone",
|
||||||
|
"push_in",
|
||||||
|
"crane_down",
|
||||||
|
"truck_right",
|
||||||
|
"tilt_down",
|
||||||
|
"elevator_doors",
|
||||||
|
"tilt_up",
|
||||||
|
"ground_level",
|
||||||
|
"pull_out",
|
||||||
|
"aerial",
|
||||||
|
"crane_up",
|
||||||
|
"eye_level"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class LumaImageModel(str, Enum):
|
class LumaImageModel(str, Enum):
|
||||||
photon_1 = "photon-1"
|
photon_1 = "photon-1"
|
||||||
photon_flash_1 = "photon-flash-1"
|
photon_flash_1 = "photon-flash-1"
|
||||||
@ -133,6 +217,10 @@ class LumaKeyframes(BaseModel):
|
|||||||
frame1: Optional[Union[LumaImageReference, LumaGenerationReference]] = Field(None, description='')
|
frame1: Optional[Union[LumaImageReference, LumaGenerationReference]] = Field(None, description='')
|
||||||
|
|
||||||
|
|
||||||
|
class LumaConceptObject(BaseModel):
|
||||||
|
key: str = Field(..., description='Camera Concept name')
|
||||||
|
|
||||||
|
|
||||||
class LumaImageGenerationRequest(BaseModel):
|
class LumaImageGenerationRequest(BaseModel):
|
||||||
prompt: str = Field(..., description='The prompt of the generation')
|
prompt: str = Field(..., description='The prompt of the generation')
|
||||||
model: LumaImageModel = Field(LumaImageModel.photon_1, description='The image model used for the generation')
|
model: LumaImageModel = Field(LumaImageModel.photon_1, description='The image model used for the generation')
|
||||||
@ -151,6 +239,7 @@ class LumaGenerationRequest(BaseModel):
|
|||||||
resolution: Optional[LumaVideoOutputResolution] = Field(None, description='The resolution of the generation')
|
resolution: Optional[LumaVideoOutputResolution] = Field(None, description='The resolution of the generation')
|
||||||
loop: Optional[bool] = Field(None, description='Whether to loop the video')
|
loop: Optional[bool] = Field(None, description='Whether to loop the video')
|
||||||
keyframes: Optional[LumaKeyframes] = Field(None, description='The keyframes of the generation')
|
keyframes: Optional[LumaKeyframes] = Field(None, description='The keyframes of the generation')
|
||||||
|
concepts: Optional[list[LumaConceptObject]] = Field(None, description='Camera Concepts to apply to generation')
|
||||||
|
|
||||||
|
|
||||||
class LumaGeneration(BaseModel):
|
class LumaGeneration(BaseModel):
|
||||||
|
|||||||
@ -38,7 +38,9 @@ from comfy_api_nodes.apis.luma_api import (
|
|||||||
LumaReferenceChain,
|
LumaReferenceChain,
|
||||||
LumaImageReference,
|
LumaImageReference,
|
||||||
LumaKeyframes,
|
LumaKeyframes,
|
||||||
|
LumaConceptChain,
|
||||||
LumaIO,
|
LumaIO,
|
||||||
|
get_luma_concepts,
|
||||||
)
|
)
|
||||||
from comfy_api_nodes.apis.recraft_api import (
|
from comfy_api_nodes.apis.recraft_api import (
|
||||||
RecraftImageGenerationRequest,
|
RecraftImageGenerationRequest,
|
||||||
@ -965,7 +967,7 @@ class FluxProUltraImageNode(ComfyNodeABC):
|
|||||||
img.save(img_byte_arr, format='PNG')
|
img.save(img_byte_arr, format='PNG')
|
||||||
return base64.b64encode(img_byte_arr.getvalue()).decode()
|
return base64.b64encode(img_byte_arr.getvalue()).decode()
|
||||||
|
|
||||||
class LumaReferenceNode:
|
class LumaReferenceNode(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
Holds an image and weight for use with Luma Generate Image node.
|
Holds an image and weight for use with Luma Generate Image node.
|
||||||
"""
|
"""
|
||||||
@ -1003,7 +1005,39 @@ class LumaReferenceNode:
|
|||||||
luma_ref.add(LumaReference(image=image, weight=round(weight, 2)))
|
luma_ref.add(LumaReference(image=image, weight=round(weight, 2)))
|
||||||
return (luma_ref, )
|
return (luma_ref, )
|
||||||
|
|
||||||
class LumaImageGenerationNode:
|
class LumaConceptsNode(ComfyNodeABC):
|
||||||
|
"""
|
||||||
|
Holds one or more Camera Concepts for use with Luma Text to Video and Luma Image to Video nodes.
|
||||||
|
"""
|
||||||
|
RETURN_TYPES = (LumaIO.LUMA_CONCEPTS,)
|
||||||
|
RETURN_NAMES = ("luma_concepts",)
|
||||||
|
DESCRIPTION = cleandoc(__doc__ or "") # Handle potential None value
|
||||||
|
FUNCTION = "create_concepts"
|
||||||
|
CATEGORY = "api node/Luma"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"concept1": (get_luma_concepts(include_none=True), ),
|
||||||
|
"concept2": (get_luma_concepts(include_none=True), ),
|
||||||
|
"concept3": (get_luma_concepts(include_none=True), ),
|
||||||
|
"concept4": (get_luma_concepts(include_none=True), ),
|
||||||
|
},
|
||||||
|
"optional": {
|
||||||
|
"luma_concepts": (LumaIO.LUMA_CONCEPTS, {
|
||||||
|
"tooltip": "Optional Camera Concepts to add to the ones chosen here."
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def create_concepts(self, concept1: str, concept2: str, concept3: str, concept4: str, luma_concepts: LumaConceptChain=None):
|
||||||
|
chain = LumaConceptChain(str_list=[concept1, concept2, concept3, concept4])
|
||||||
|
if luma_concepts is not None:
|
||||||
|
chain = luma_concepts.clone_and_merge(chain)
|
||||||
|
return (chain,)
|
||||||
|
|
||||||
|
class LumaImageGenerationNode(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
Generates images synchronously based on prompt and aspect ratio.
|
Generates images synchronously based on prompt and aspect ratio.
|
||||||
"""
|
"""
|
||||||
@ -1126,7 +1160,7 @@ class LumaImageGenerationNode:
|
|||||||
chain = LumaReferenceChain(first_ref=LumaReference(image=style_image, weight=weight))
|
chain = LumaReferenceChain(first_ref=LumaReference(image=style_image, weight=weight))
|
||||||
return self._convert_luma_refs(chain, max_refs=1, auth_token=auth_token)
|
return self._convert_luma_refs(chain, max_refs=1, auth_token=auth_token)
|
||||||
|
|
||||||
class LumaImageModifyNode:
|
class LumaImageModifyNode(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
Modifies images synchronously based on prompt and aspect ratio.
|
Modifies images synchronously based on prompt and aspect ratio.
|
||||||
"""
|
"""
|
||||||
@ -1211,7 +1245,7 @@ class LumaImageModifyNode:
|
|||||||
img = process_image_response(img_response)
|
img = process_image_response(img_response)
|
||||||
return (img,)
|
return (img,)
|
||||||
|
|
||||||
class LumaTextToVideoGenerationNode:
|
class LumaTextToVideoGenerationNode(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
Generates videos synchronously based on prompt and output_size.
|
Generates videos synchronously based on prompt and output_size.
|
||||||
"""
|
"""
|
||||||
@ -1254,6 +1288,9 @@ class LumaTextToVideoGenerationNode:
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
|
"luma_concepts": (LumaIO.LUMA_CONCEPTS, {
|
||||||
|
"tooltip": "Optional Camera Concepts to dictate camera motion via the Luma Concepts node."
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
"hidden": {
|
"hidden": {
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
||||||
@ -1261,7 +1298,7 @@ class LumaTextToVideoGenerationNode:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def api_call(self, prompt: str, model: str, aspect_ratio: str, resolution: str, duration: str, loop: bool, seed,
|
def api_call(self, prompt: str, model: str, aspect_ratio: str, resolution: str, duration: str, loop: bool, seed,
|
||||||
auth_token=None, **kwargs):
|
luma_concepts: LumaConceptChain=None, auth_token=None, **kwargs):
|
||||||
operation = SynchronousOperation(
|
operation = SynchronousOperation(
|
||||||
endpoint=ApiEndpoint(
|
endpoint=ApiEndpoint(
|
||||||
path="/proxy/luma/generations",
|
path="/proxy/luma/generations",
|
||||||
@ -1276,6 +1313,7 @@ class LumaTextToVideoGenerationNode:
|
|||||||
aspect_ratio=aspect_ratio,
|
aspect_ratio=aspect_ratio,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
loop=loop,
|
loop=loop,
|
||||||
|
concepts=luma_concepts.create_api_model() if luma_concepts else None
|
||||||
),
|
),
|
||||||
auth_token=auth_token
|
auth_token=auth_token
|
||||||
)
|
)
|
||||||
@ -1298,7 +1336,7 @@ class LumaTextToVideoGenerationNode:
|
|||||||
vid_response = requests.get(response_poll.assets.video)
|
vid_response = requests.get(response_poll.assets.video)
|
||||||
return (VideoFromFile(BytesIO(vid_response.content)), )
|
return (VideoFromFile(BytesIO(vid_response.content)), )
|
||||||
|
|
||||||
class LumaImageToVideoGenerationNode:
|
class LumaImageToVideoGenerationNode(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
Generates videos synchronously based on prompt, input images, and output_size.
|
Generates videos synchronously based on prompt, input images, and output_size.
|
||||||
"""
|
"""
|
||||||
@ -1347,6 +1385,9 @@ class LumaImageToVideoGenerationNode:
|
|||||||
"last_image": (IO.IMAGE, {
|
"last_image": (IO.IMAGE, {
|
||||||
"tooltip": "Last frame of generated video."
|
"tooltip": "Last frame of generated video."
|
||||||
}),
|
}),
|
||||||
|
"luma_concepts": (LumaIO.LUMA_CONCEPTS, {
|
||||||
|
"tooltip": "Optional Camera Concepts to dictate camera motion via the Luma Concepts node."
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
"hidden": {
|
"hidden": {
|
||||||
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
"auth_token": "AUTH_TOKEN_COMFY_ORG",
|
||||||
@ -1354,7 +1395,7 @@ class LumaImageToVideoGenerationNode:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def api_call(self, prompt: str, model: str, resolution: str, duration: str, loop: bool, seed,
|
def api_call(self, prompt: str, model: str, resolution: str, duration: str, loop: bool, seed,
|
||||||
first_image: torch.Tensor=None, last_image: torch.Tensor=None,
|
first_image: torch.Tensor=None, last_image: torch.Tensor=None, luma_concepts: LumaConceptChain=None,
|
||||||
auth_token=None, **kwargs):
|
auth_token=None, **kwargs):
|
||||||
if first_image is None and last_image is None:
|
if first_image is None and last_image is None:
|
||||||
raise Exception("At least one of first_image and last_image requires an input.")
|
raise Exception("At least one of first_image and last_image requires an input.")
|
||||||
@ -1370,11 +1411,12 @@ class LumaImageToVideoGenerationNode:
|
|||||||
request=LumaGenerationRequest(
|
request=LumaGenerationRequest(
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
model=model,
|
model=model,
|
||||||
aspect_ratio=LumaAspectRatio.ratio_16_9,
|
aspect_ratio=LumaAspectRatio.ratio_16_9, # ignored, but still needed by the API for some reason
|
||||||
resolution=resolution,
|
resolution=resolution,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
loop=loop,
|
loop=loop,
|
||||||
keyframes=keyframes
|
keyframes=keyframes,
|
||||||
|
concepts=luma_concepts.create_api_model() if luma_concepts else None
|
||||||
),
|
),
|
||||||
auth_token=auth_token
|
auth_token=auth_token
|
||||||
)
|
)
|
||||||
@ -1720,9 +1762,10 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"FluxProUltraImageNode": FluxProUltraImageNode,
|
"FluxProUltraImageNode": FluxProUltraImageNode,
|
||||||
"LumaImageNode": LumaImageGenerationNode,
|
"LumaImageNode": LumaImageGenerationNode,
|
||||||
"LumaImageModifyNode": LumaImageModifyNode,
|
"LumaImageModifyNode": LumaImageModifyNode,
|
||||||
"LumaReferenceNode": LumaReferenceNode,
|
|
||||||
"LumaVideoNode": LumaTextToVideoGenerationNode,
|
"LumaVideoNode": LumaTextToVideoGenerationNode,
|
||||||
"LumaImageToVideoNode": LumaImageToVideoGenerationNode,
|
"LumaImageToVideoNode": LumaImageToVideoGenerationNode,
|
||||||
|
"LumaReferenceNode": LumaReferenceNode,
|
||||||
|
"LumaConceptsNode": LumaConceptsNode,
|
||||||
"RecraftTextToImageNode": RecraftTextToImageNode,
|
"RecraftTextToImageNode": RecraftTextToImageNode,
|
||||||
#"RecraftStyleV3RealisticImage": RecraftStyleV3RealisticImageNode,
|
#"RecraftStyleV3RealisticImage": RecraftStyleV3RealisticImageNode,
|
||||||
"RecraftStyleV3DigitalIllustration": RecraftStyleV3DigitalIllustrationNode,
|
"RecraftStyleV3DigitalIllustration": RecraftStyleV3DigitalIllustrationNode,
|
||||||
@ -1740,9 +1783,10 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
|||||||
"FluxProUltraImageNode": "Flux 1.1 [pro] Ultra Image",
|
"FluxProUltraImageNode": "Flux 1.1 [pro] Ultra Image",
|
||||||
"LumaImageNode": "Luma Text to Image",
|
"LumaImageNode": "Luma Text to Image",
|
||||||
"LumaImageModifyNode": "Luma Image to Image",
|
"LumaImageModifyNode": "Luma Image to Image",
|
||||||
"LumaReferenceNode": "Luma Reference",
|
|
||||||
"LumaVideoNode": "Luma Text to Video",
|
"LumaVideoNode": "Luma Text to Video",
|
||||||
"LumaImageToVideoNode": "Luma Image to Video",
|
"LumaImageToVideoNode": "Luma Image to Video",
|
||||||
|
"LumaReferenceNode": "Luma Reference",
|
||||||
|
"LumaConceptsNode": "Luma Concepts",
|
||||||
"RecraftTextToImageNode": "Recraft Text to Image",
|
"RecraftTextToImageNode": "Recraft Text to Image",
|
||||||
"RecraftStyleV3RealisticImage": "Recraft Style - Realistic Image",
|
"RecraftStyleV3RealisticImage": "Recraft Style - Realistic Image",
|
||||||
"RecraftStyleV3DigitalIllustration": "Recraft Style - Digital Illustration",
|
"RecraftStyleV3DigitalIllustration": "Recraft Style - Digital Illustration",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user