update-inference (#4)
Browse files- Update inference.py (7b9f053b980d37b4af43b808e6cfada81caee869)
- Update app.py (9742f923e6f1247a0c029af3dce3613733f5530c)
Files changed (2)
- app.py+1-1
- inference.py+11-15
345 unmodified lines346347348349350351352345 unmodified lineswith gr.Column():with gr.Tab("image-to-video") as image_tab:video_i_hidden = gr.Textbox(label="video_i", visible=False, value=None)image_i2v = gr.Image(label="Input Image", type="filepath", sources=["upload", "webcam"])i2v_prompt = gr.Textbox(label="Prompt", value="The creature from the image starts to move", lines=3)i2v_button = gr.Button("Generate Image-to-Video", variant="primary")with gr.Tab("text-to-video") as text_tab:345 unmodified lines346347348349350351352345 unmodified lineswith gr.Column():with gr.Tab("image-to-video") as image_tab:video_i_hidden = gr.Textbox(label="video_i", visible=False, value=None)image_i2v = gr.Image(label="Input Image", type="filepath", sources=["upload", "webcam", "clipboard"])i2v_prompt = gr.Textbox(label="Prompt", value="The creature from the image starts to move", lines=3)i2v_button = gr.Button("Generate Image-to-Video", variant="primary")with gr.Tab("text-to-video") as text_tab:
10 unmodified lines11121314151618 unmodified lines35363738394055 unmodified lines96979899100101102163 unmodified lines266267268269270271272273274275276277278128 unmodified lines4074084094104114124138 unmodified lines422423424425426427428429430431432433182 unmodified lines616617618619620621622152 unmodified lines77577677777810 unmodified linesimport jsonimport numpy as npimport torchfrom safetensors import safe_openfrom PIL import Imagefrom transformers import (18 unmodified linesfrom ltx_video.schedulers.rf import RectifiedFlowSchedulerfrom ltx_video.utils.skip_layer_strategy import SkipLayerStrategyfrom ltx_video.models.autoencoders.latent_upsampler import LatentUpsamplerMAX_HEIGHT = 720MAX_WIDTH = 128055 unmodified linesimage = image.crop((x_start, y_start, x_start + new_width, y_start + new_height))if not just_crop:image = image.resize((target_width, target_height))frame_tensor = torch.tensor(np.array(image)).permute(2, 0, 1).float()frame_tensor = (frame_tensor / 127.5) - 1.0# Create 5D tensor: (batch_size=1, channels=3, num_frames=1, height, width)return frame_tensor.unsqueeze(0).unsqueeze(2)163 unmodified lineshelp="Path to the input video (or imaage) to be modified using the video-to-video pipeline",)parser.add_argument("--strength",type=float,default=1.0,help="Editing strength (noising level) for video-to-video pipeline.",)# Conditioning argumentsparser.add_argument("--conditioning_media_paths",128 unmodified linesnegative_prompt: str,offload_to_cpu: bool,input_media_path: Optional[str] = None,strength: Optional[float] = 1.0,conditioning_media_paths: Optional[List[str]] = None,conditioning_strengths: Optional[List[float]] = None,conditioning_start_frames: Optional[List[int]] = None,8 unmodified linesmodels_dir = "MODEL_DIR"#ltxv_model_name_or_path = pipeline_config["checkpoint_path"]ltxv_model_name_or_path = "ltxv-13b-0.9.7-distilled-rc3.safetensors"if not os.path.isfile(ltxv_model_name_or_path):ltxv_model_path = hf_hub_download(repo_id="LTX-Colab/LTX-Video-Preview",#repo_id="Lightricks/LTX-Video",filename=ltxv_model_name_or_path,local_dir=models_dir,repo_type="model",182 unmodified linesframe_rate=frame_rate,**sample,media_items=media_item,strength=strength,conditioning_items=conditioning_items,is_video=True,vae_per_channel_normalize=True,152 unmodified linesif __name__ == "__main__":main()10 unmodified lines1112131415161718 unmodified lines3637383940414255 unmodified lines9899100101102103104105106107108109163 unmodified lines273274275276277278128 unmodified lines4074084094104114128 unmodified lines421422423424425426427428429430182 unmodified lines613614615616617618152 unmodified lines77177277377410 unmodified linesimport jsonimport numpy as npimport torchimport cv2from safetensors import safe_openfrom PIL import Imagefrom transformers import (18 unmodified linesfrom ltx_video.schedulers.rf import RectifiedFlowSchedulerfrom ltx_video.utils.skip_layer_strategy import SkipLayerStrategyfrom ltx_video.models.autoencoders.latent_upsampler import LatentUpsamplerimport ltx_video.pipelines.crf_compressor as crf_compressorMAX_HEIGHT = 720MAX_WIDTH = 128055 unmodified linesimage = image.crop((x_start, y_start, x_start + new_width, y_start + new_height))if not just_crop:image = image.resize((target_width, target_height))image = np.array(image)image = cv2.GaussianBlur(image, (3, 3), 0)frame_tensor = torch.from_numpy(image).float()frame_tensor = crf_compressor.compress(frame_tensor / 255.0) * 255.0frame_tensor = frame_tensor.permute(2, 0, 1)frame_tensor = (frame_tensor / 127.5) - 1.0# Create 5D tensor: (batch_size=1, channels=3, num_frames=1, height, width)return frame_tensor.unsqueeze(0).unsqueeze(2)163 unmodified lineshelp="Path to the input video (or imaage) to be modified using the video-to-video pipeline",)# Conditioning argumentsparser.add_argument("--conditioning_media_paths",128 unmodified linesnegative_prompt: str,offload_to_cpu: bool,input_media_path: Optional[str] = None,conditioning_media_paths: Optional[List[str]] = None,conditioning_strengths: Optional[List[float]] = None,conditioning_start_frames: Optional[List[int]] = None,8 unmodified linesmodels_dir = "MODEL_DIR"ltxv_model_name_or_path = pipeline_config["checkpoint_path"]if not os.path.isfile(ltxv_model_name_or_path):ltxv_model_path = hf_hub_download(repo_id="Lightricks/LTX-Video",filename=ltxv_model_name_or_path,local_dir=models_dir,repo_type="model",182 unmodified linesframe_rate=frame_rate,**sample,media_items=media_item,conditioning_items=conditioning_items,is_video=True,vae_per_channel_normalize=True,152 unmodified linesif __name__ == "__main__":main()
app.py+1-1
inference.py+11-15