Spaces:
Runtime error
Runtime error
import argparse | |
import sys | |
from typing import Any, Dict, Literal, Optional | |
sys.path.append("./cosmos-transfer1") | |
from cosmos_transfer1.diffusion.inference.inference_utils import valid_hint_keys | |
def load_controlnet_specs(controlnet_specs_in: dict) -> Dict[str, Any]: | |
controlnet_specs = {} | |
args = {} | |
for hint_key, config in controlnet_specs_in.items(): | |
if hint_key in valid_hint_keys: | |
controlnet_specs[hint_key] = config | |
else: | |
if isinstance(config, dict): | |
raise ValueError(f"Invalid hint_key: {hint_key}. Must be one of {valid_hint_keys}") | |
else: | |
args[hint_key] = config | |
continue | |
return controlnet_specs, args | |
def parse_arguments( | |
controlnet_specs_in: dict, | |
prompt: str = "The video captures a stunning, photorealistic scene with remarkable attention to detail, giving it a lifelike appearance that is almost indistinguishable from reality. It appears to be from a high-budget 4K movie, showcasing ultra-high-definition quality with impeccable resolution.", # noqa: E501 | |
negative_prompt: str = "The video captures a game playing, with bad crappy graphics and cartoonish frames. It represents a recording of old outdated games. The lighting looks very fake. The textures are very raw and basic. The geometries are very primitive. The images are very pixelated and of poor CG quality. There are many subtitles in the footage. Overall, the video is unrealistic at all.", # noqa: E501 | |
input_video_path: str = "", | |
num_input_frames: int = 1, | |
sigma_max: float = 70.0, | |
blur_strength: Literal["very_low", "low", "medium", "high", "very_high"] = "medium", | |
canny_threshold: Literal["very_low", "low", "medium", "high", "very_high"] = "medium", | |
is_av_sample: bool = False, | |
checkpoint_dir: str = "checkpoints", | |
tokenizer_dir: str = "Cosmos-Tokenize1-CV8x8x8-720p", | |
video_save_name: str = "output", | |
video_save_folder: str = "outputs/", | |
batch_input_path: Optional[str] = None, | |
batch_size: int = 1, | |
num_steps: int = 35, | |
guidance: float = 5, | |
fps: int = 24, | |
seed: int = 1, | |
num_gpus: Literal[1] = 1, | |
offload_diffusion_transformer: bool = False, | |
offload_text_encoder_model: bool = False, | |
offload_guardrail_models: bool = False, | |
upsample_prompt: bool = False, | |
offload_prompt_upsampler: bool = False, | |
use_distilled: bool = False, | |
) -> argparse.Namespace: | |
""" | |
Parse input of control to world generation | |
:param str controlnet_specs_in: multicontrolnet configurations dict | |
:param str prompt: prompt which the sampled video condition on | |
:param str negative_prompt: negative prompt which the sampled video condition on | |
:param str input_video_path: Optional input RGB video path | |
:param int num_input_frames: Number of conditional frames for long video generation | |
:param float sigma_max: sigma_max for partial denoising | |
:param str blur_strength: blur strength | |
:param str canny_threshold: blur strength of canny threshold applied to input. Lower means less blur or more detected edges, which means higher fidelity to input | |
:param bool is_av_sample: Whether the model is an driving post-training model | |
:param str checkpoint_dir: Base directory containing model checkpoints | |
:param str tokenizer_dir: Tokenizer weights directory relative to checkpoint_dir | |
:param str video_save_name: Output filename for generating a single video | |
:param str video_save_folder: Output folder for generating a batch of videos | |
:param str batch_input_path: Path to a JSONL file of input prompts for generating a batch of videos | |
:param int batch_size: Batch size | |
:param int num_steps: Number of diffusion sampling steps | |
:param float guidance: Classifier-free guidance scale value | |
:param int fps: FPS of the output video | |
:param int seed: Random seed | |
:param int num_gpus: Number of GPUs used to run inference in parallel | |
:param bool offload_diffusion_transformer: Offload DiT after inference | |
:param bool offload_text_encoder_model: Offload text encoder model after inference | |
:param bool offload_guardrail_models: Offload guardrail models after inference | |
:param bool upsample_prompt: Upsample prompt using Pixtral upsampler model | |
:param bool offload_prompt_upsampler: Offload prompt upsampler model after inference | |
:param bool use_distilled: Use distilled ControlNet model variant | |
""" | |
cmd_args = argparse.Namespace( | |
prompt=prompt, | |
negative_prompt=negative_prompt, | |
input_video_path=input_video_path, | |
num_input_frames=num_input_frames, | |
sigma_max=sigma_max, | |
blur_strength=blur_strength, | |
canny_threshold=canny_threshold, | |
is_av_sample=is_av_sample, | |
checkpoint_dir=checkpoint_dir, | |
tokenizer_dir=tokenizer_dir, | |
video_save_name=video_save_name, | |
video_save_folder=video_save_folder, | |
batch_input_path=batch_input_path, | |
batch_size=batch_size, | |
num_steps=num_steps, | |
guidance=guidance, | |
fps=fps, | |
seed=seed, | |
num_gpus=num_gpus, | |
offload_diffusion_transformer=offload_diffusion_transformer, | |
offload_text_encoder_model=offload_text_encoder_model, | |
offload_guardrail_models=offload_guardrail_models, | |
upsample_prompt=upsample_prompt, | |
offload_prompt_upsampler=offload_prompt_upsampler, | |
use_distilled=use_distilled, | |
) | |
# Load and parse JSON input | |
control_inputs, json_args = load_controlnet_specs(controlnet_specs_in) | |
# if parameters not set on command line, use the ones from the controlnet_specs | |
# if both not set use command line defaults | |
for key in json_args: | |
if f"--{key}" not in sys.argv: | |
setattr(cmd_args, key, json_args[key]) | |
return cmd_args, control_inputs | |