enhanced ttv

This commit is contained in:
Saifeddine ALOUI 2025-03-07 22:42:37 +01:00
parent d7f3a409f7
commit 1ec1422b86
2 changed files with 46 additions and 13 deletions

View File

@ -41,10 +41,43 @@ class LollmsLumaLabs(LollmsTTV):
"authorization": f"Bearer {self.service_config.api_key}",
"content-type": "application/json"
}
def determine_aspect_ratio(self, width, height):
# Define common aspect ratios and their tolerances
aspect_ratios = {
"1:1": (1, 1, 0.05),
"4:3": (4, 3, 0.1),
"16:9": (16, 9, 0.1),
"16:10": (16, 10, 0.1),
"21:9": (21, 9, 0.1),
"3:2": (3, 2, 0.1),
"5:4": (5, 4, 0.1),
"2:1": (2, 1, 0.1)
}
def generate_video(self, prompt: str, aspect_ratio: str = "16:9",
# Calculate the aspect ratio of the input dimensions
current_aspect = width / height
best_match = None
min_diff = float('inf')
for ratio, (w, h, tolerance) in aspect_ratios.items():
expected_aspect = w / h
diff = abs(expected_aspect - current_aspect)
if diff < min_diff and diff < tolerance:
min_diff = diff
best_match = ratio
if best_match:
return best_match
else:
# If no standard aspect ratio matches within tolerance, return the closest one
return f"{int(width)}:{int(height)}"
def generate_video(self, prompt: str, width, height,
loop: bool = False, num_frames: int = 60,
fps: int = 30, keyframes: Optional[Dict] = None)-> str:
aspect_ratio = self.determine_aspect_ratio(width, height)
payload = {
"prompt": prompt,
"aspect_ratio": aspect_ratio,

View File

@ -32,8 +32,13 @@ class LollmsNovitaAITextToVideo(LollmsTTV):
ConfigTemplate([
{"name":"api_key", "type":"str", "value":api_key, "help":"A valid Novita AI key to generate text using anthropic api"},
{"name":"generation_engine","type":"str","value":"stable_diffusion", "options": ["stable_diffusion", "hunyuan-video-fast", "wan-t2v"], "help":"The engine name"},
{"name":"sd_model_name","type":"str","value":"darkSushiMixMix_225D_64380.safetensors", "options": ["darkSushiMixMix_225D_64380.safetensors"], "help":"The model name"}
{"name":"n_frames","type":"int","value":129, "help":"The number of frames in the video"}
{"name":"sd_model_name","type":"str","value":"darkSushiMixMix_225D_64380.safetensors", "options": ["darkSushiMixMix_225D_64380.safetensors"], "help":"The model name"},
{"name":"n_frames","type":"int","value":129, "help":"The number of frames in the video"},
{"name":"guidance_scale", "type":"float", "value":7.5, "help":"The guidance scale for the generation"},
{"name":"loras", "type":"str", "value":None, "help":"List of LoRA configurations"},
{"name":"embeddings", "type":"str", "value":None, "help":"List of embedding configurations"},
{"name":"closed_loop", "type":"bool", "value":False, "help":"Whether to use closed loop generation"},
{"name":"clip_skip", "type":"int", "value":0, "help":"Number of layers to skip in CLIP"}
]),
BaseConfig(config={
"api_key": "", # use avx2
@ -75,11 +80,6 @@ class LollmsNovitaAITextToVideo(LollmsTTV):
steps: int = 20,
seed: int = -1,
nb_frames: int = None,
guidance_scale: Optional[float] = None,
loras: Optional[List[Dict[str, Any]]] = None,
embeddings: Optional[List[Dict[str, Any]]] = None,
closed_loop: Optional[bool] = None,
clip_skip: Optional[int] = None,
output_dir:str | Path =None,
) -> str:
"""
@ -174,12 +174,12 @@ class LollmsNovitaAITextToVideo(LollmsTTV):
}
],
"negative_prompt": negative_prompt,
"guidance_scale": guidance_scale,
"guidance_scale": self.service_config.guidance_scale,
"seed": seed,
"loras": loras,
"embeddings": embeddings,
"closed_loop": closed_loop,
"clip_skip": clip_skip
"loras": self.service_config.loras,
"embeddings": self.service_config.embeddings,
"closed_loop": self.service_config.closed_loop,
"clip_skip": self.service_config.clip_skip
}
# Remove None values from the payload to avoid sending null fields
payload = {k: v for k, v in payload.items() if v is not None}