import os import subprocess import sys # Disable torch.compile / dynamo before any torch import os.environ["TORCH_COMPILE_DISABLE"] = "1" os.environ["TORCHDYNAMO_DISABLE"] = "1" # Install xformers for memory-efficient attention subprocess.run([sys.executable, "-m", "pip", "install", "xformers==0.0.32.post2", "--no-build-isolation"], check=False) # Clone LTX-2 repo and install packages LTX_REPO_URL = "https://github.com/Lightricks/LTX-2.git" LTX_REPO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "LTX-2") LTX_COMMIT = "ae855f8538843825f9015a419cf4ba5edaf5eec2" # known working commit with decode_video if not os.path.exists(LTX_REPO_DIR): print(f"Cloning {LTX_REPO_URL}...") subprocess.run(["git", "clone", LTX_REPO_URL, LTX_REPO_DIR], check=True) subprocess.run(["git", "checkout", LTX_COMMIT], cwd=LTX_REPO_DIR, check=True) print("Installing ltx-core and ltx-pipelines from cloned repo...") subprocess.run( [sys.executable, "-m", "pip", "install", "--force-reinstall", "--no-deps", "-e", os.path.join(LTX_REPO_DIR, "packages", "ltx-core"), "-e", os.path.join(LTX_REPO_DIR, "packages", "ltx-pipelines")], check=True, ) sys.path.insert(0, os.path.join(LTX_REPO_DIR, "packages", "ltx-pipelines", "src")) sys.path.insert(0, os.path.join(LTX_REPO_DIR, "packages", "ltx-core", "src")) _I2V_SYSTEM_PROMPT = ( "You are a Creative Assistant writing concise, action-focused image-to-video prompts." " Given an image (first frame) and user Raw Input Prompt, generate a prompt to guide" " video generation from that image.\n\n" "#### Guidelines:\n" "- Analyze the Image: Identify Subject, Setting, Elements, Style and Mood.\n" "- Follow user Raw Input Prompt: Include all requested motion, actions, camera movements," " audio, and details. If in conflict with the image, prioritize user request while" " maintaining visual consistency (describe transition from image to user's scene).\n" "- Describe only changes from the image: Don't reiterate established visual details." " Inaccurate descriptions may cause scene cuts.\n" "- Active language: Use present-progressive verbs (\"is walking,\" \"speaking\")." " If no action specified, describe natural movements.\n" "- Chronological flow: Use temporal connectors (\"as,\" \"then,\" \"while\").\n" "- Audio layer: Describe complete soundscape throughout the prompt alongside" " actions\u2014NOT at the end. Align audio intensity with action tempo. Include natural" " background audio, ambient sounds, effects, speech or music (when requested). Be specific" " (e.g., \"soft footsteps on tile\") not vague (e.g., \"ambient sound\").\n" "- Speech (only when requested): Provide exact words in quotes with character's" " visual/voice characteristics (e.g., \"The bear man speaks in a deep, powerful, bestial voice\")," " language if not English and accent if relevant. If general conversation mentioned without" " text, generate contextual quoted dialogue. (i.e., \"The man is talking\" input -> the" " output should include exact spoken words, like: \"The man is talking in an excited voice" " saying: 'You won't believe what I just saw!' His hands gesture expressively as he speaks," " eyebrows raised with enthusiasm. The ambient sound of a quiet room underscores his" " animated speech.\")\n" "- Style: Include visual style at beginning: \"Style: