Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files91 unmodified lines92939495969798168 unmodified lines26726826927027127227327418 unmodified lines29329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336431 unmodified lines39639739839940040191 unmodified lines"Fine lunar dust lifts and drifts outward with each movement, floating ""in slow arcs before settling back onto the ground.")DEFAULT_FRAME_RATE = 48.0# Resolution presets: (width, height)RESOLUTIONS = {168 unmodified lines# Model reposLTX_MODEL_REPO = "Lightricks/LTX-2.3"GEMMA_REPO ="Lightricks/gemma-3-12b-it-qat-q4_0-unquantized"GEMMA_ABLITERATED_REPO = "Sikaworld1990/gemma-3-12b-it-abliterated-sikaworld-high-fidelity-edition-Ltx-2"GEMMA_ABLITERATED_FILE = "gemma-3-12b-it-abliterated-sikaworld-high-fidelity-edition.safetensors"# Download model checkpointsprint("=" * 80)18 unmodified lineslocal_dir_use_symlinks=False,)spatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.1.safetensors")print("[Gemma] Setting up abliterated Gemma text encoder...")MERGED_WEIGHTS = "/tmp/abliterated_gemma_merged.safetensors"gemma_root = "/tmp/abliterated_gemma"os.makedirs(gemma_root, exist_ok=True)gemma_official_dir = snapshot_download(repo_id=GEMMA_REPO,ignore_patterns=["*.safetensors", "*.safetensors.index.json"],)for fname in os.listdir(gemma_official_dir):src = os.path.join(gemma_official_dir, fname)dst = os.path.join(gemma_root, fname)if os.path.isfile(src) and not fname.endswith(".safetensors") and fname != "model.safetensors.index.json":if not os.path.exists(dst):os.symlink(src, dst)if os.path.exists(MERGED_WEIGHTS):print("[Gemma] Using cached merged weights")else:abliterated_weights_path = hf_hub_download(repo_id=GEMMA_ABLITERATED_REPO,filename=GEMMA_ABLITERATED_FILE,)index_path = hf_hub_download(repo_id=GEMMA_REPO,filename="model.safetensors.index.json")with open(index_path) as f:weight_index = json.load(f)vision_keys = {}for key, shard in weight_index["weight_map"].items():if "vision_tower" in key or "multi_modal_projector" in key:vision_keys[key] = shardneeded_shards = set(vision_keys.values())shard_paths = {}for shard_name in needed_shards:shard_paths[shard_name] = hf_hub_download(repo_id=GEMMA_REPO,filename=shard_name)_fp8_types = {torch.float8_e4m3fn, torch.float8_e5m2}raw = load_file(abliterated_weights_path)merged = {}for key, tensor in raw.items():t = tensor.to(torch.bfloat16) if tensor.dtype in _fp8_types else tensormerged[f"language_model.{key}"] = tdel rawfor key, shard_name in vision_keys.items():with safe_open(shard_paths[shard_name], framework="pt") as f:merged[key] = f.get_tensor(key)save_file(merged, MERGED_WEIGHTS)del mergedgc.collect()weight_link = os.path.join(gemma_root, "model.safetensors")if os.path.exists(weight_link):os.remove(weight_link)os.symlink(MERGED_WEIGHTS, weight_link)print(f"[Gemma] Root ready: {gemma_root}")# ---- Insert block (LoRA downloads) between lines 268 and 269 ----# LoRA repo + download the requested LoRA adapters31 unmodified linesprint(f"Checkpoint: {checkpoint_path}")print(f"Spatial upsampler: {spatial_upsampler_path}")# Initialize pipeline WITH text encoder and optional audio support# ---- Replace block (pipeline init) lines 275-281 ----91 unmodified lines92939495969798168 unmodified lines26726826927027127218 unmodified lines29129229329429529629729831 unmodified lines33033133233333433533691 unmodified lines"Fine lunar dust lifts and drifts outward with each movement, floating ""in slow arcs before settling back onto the ground.")DEFAULT_FRAME_RATE = 25.0# Resolution presets: (width, height)RESOLUTIONS = {168 unmodified lines# Model reposLTX_MODEL_REPO = "Lightricks/LTX-2.3"GEMMA_REPO ="Lightricks/gemma-3-12b-it-qat-q4_0-unquantized"# Download model checkpointsprint("=" * 80)18 unmodified lineslocal_dir_use_symlinks=False,)spatial_upsampler_path = hf_hub_download(repo_id=LTX_MODEL_REPO, filename="ltx-2.3-spatial-upscaler-x2-1.1.safetensors")gemma_root = snapshot_download(repo_id=GEMMA_REPO, token=HF_TOKEN)# ---- Insert block (LoRA downloads) between lines 268 and 269 ----# LoRA repo + download the requested LoRA adapters31 unmodified linesprint(f"Checkpoint: {checkpoint_path}")print(f"Spatial upsampler: {spatial_upsampler_path}")print(f"[Gemma] Root ready: {gemma_root}")# Initialize pipeline WITH text encoder and optional audio support# ---- Replace block (pipeline init) lines 275-281 ----
app.py+3-68