Prompt Sequence Interpolator now returns prompt sequence
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# MBM's Music Visualizer: Interpolated Prompt Sequence
|
||||
# Represents and facilitates building of a sequence of interpolated prompts.
|
||||
# Represents and facilitates building of a sequence of prompts with weighted interpolation.
|
||||
|
||||
# Imports
|
||||
import torch
|
||||
@@ -9,7 +9,7 @@ from .mbmPromptSequence import MbmPrompt
|
||||
# Classes
|
||||
class InterpPromptSequence:
|
||||
"""
|
||||
Represents and facilitates building of a sequence of interpolated prompts.
|
||||
Represents and facilitates building of a sequence of prompts with weighted interpolation.
|
||||
"""
|
||||
# Constructor
|
||||
def __init__(self, start: MbmPrompt, end: MbmPrompt, modifiers: torch.Tensor) -> None:
|
||||
@@ -93,6 +93,20 @@ class InterpPromptSequence:
|
||||
self.positivePools = self.positivePools[:length]
|
||||
self.negativePools = self.negativePools[:length]
|
||||
|
||||
def asPromptSequence(self) -> list[MbmPrompt]:
|
||||
"""
|
||||
Returns the sequence as a list of MbmPrompt objects.
|
||||
"""
|
||||
return [
|
||||
MbmPrompt(
|
||||
self.positives[i],
|
||||
self.negatives[i],
|
||||
positivePool=self.positivePools[i],
|
||||
negativePool=self.negativePools[i]
|
||||
)
|
||||
for i in range(len(self.positives))
|
||||
]
|
||||
|
||||
def _weightedInterpolation(self, start: torch.Tensor, stop: torch.Tensor, weights: torch.Tensor) -> torch.Tensor:
|
||||
"""
|
||||
Interpolates between `start` and `stop` based on the given `weights` for each step in the interpolation.
|
||||
|
||||
@@ -28,6 +28,8 @@ class MbmPrompt:
|
||||
self.positivePool = positivePool
|
||||
self.negativePool = negativePool
|
||||
|
||||
# TODO: Add additional "data" parameter for additional data to be stored with the prompt
|
||||
|
||||
# Python Functions
|
||||
def __repr__(self) -> str:
|
||||
return f"MbmPrompt(positive={self.positive.shape}, negative={self.negative.shape}, positivePool={self.positivePool.shape if self.positivePool is not None else 'None'}, negativePool={self.negativePool.shape if self.negativePool is not None else 'None'})"
|
||||
|
||||
@@ -56,42 +56,34 @@ class PromptSequenceInterpolator:
|
||||
# Set intial prompts
|
||||
if promptCount > 1:
|
||||
# Calculate linear interpolation between prompts
|
||||
promptSeq: Optional[InterpPromptSequence] = None
|
||||
interpPromptSeq: Optional[InterpPromptSequence] = None
|
||||
relDesiredFrames = math.ceil(desiredFrames / (promptCount - 1))
|
||||
for i in range(promptCount - 1):
|
||||
# Calculate modifiers for this section
|
||||
curModifiers = feat_mods[(relDesiredFrames * i):(relDesiredFrames * (i + 1))]
|
||||
|
||||
# Build prompt interpolation
|
||||
if promptSeq is None:
|
||||
if interpPromptSeq is None:
|
||||
# Start intial prompt sequence
|
||||
promptSeq = InterpPromptSequence(prompts[i], prompts[i + 1], curModifiers)
|
||||
interpPromptSeq = InterpPromptSequence(prompts[i], prompts[i + 1], curModifiers)
|
||||
else:
|
||||
# Expand prompt sequence
|
||||
promptSeq.addToSequence(prompts[i], prompts[i + 1], curModifiers)
|
||||
interpPromptSeq.addToSequence(prompts[i], prompts[i + 1], curModifiers)
|
||||
|
||||
# Trim off any extra frames produced from ceil to int
|
||||
promptSeq.trimToLength(desiredFrames)
|
||||
interpPromptSeq.trimToLength(desiredFrames)
|
||||
|
||||
# Set the initial prompt
|
||||
promptPos = MbmPrompt.buildComfyUiPrompt(
|
||||
promptSeq.positives[0],
|
||||
promptSeq.positivePools[0]
|
||||
)
|
||||
promptNeg = MbmPrompt.buildComfyUiPrompt(
|
||||
promptSeq.negatives[0],
|
||||
promptSeq.negativePools[0]
|
||||
)
|
||||
# Build the prompt sequence
|
||||
promptSeq = interpPromptSeq.asPromptSequence()
|
||||
elif promptCount == 1:
|
||||
# Set single prompt
|
||||
promptPos = prompts[0].positivePrompt()
|
||||
promptNeg = prompts[0].negativePrompt()
|
||||
# Send it onward
|
||||
promptSeq = prompts
|
||||
else:
|
||||
# No prompts
|
||||
raise ValueError("No prompts were provided to the Music Visualizer node. At least one prompt is required.")
|
||||
# No prompts my guy
|
||||
raise ValueError("At least one prompt is required.")
|
||||
|
||||
return (
|
||||
# TODO: prompt sequence
|
||||
promptSeq,
|
||||
# TODO: charts
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user