File size: 96,057 Bytes
e8b6587 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 | """LTX-2.5 Space entrypoint.
Own only startup-sensitive runtime assignment, thin callback bridges, top-level
Gradio composition, and event wiring here. Reusable feature logic and concrete
UI sub-surfaces belong under ``ltx/``.
"""
import os
# Must precede torch import. Keep the legacy alias as well as the current name.
os.environ.setdefault("PYTORCH_ALLOC_CONF", "backend:cudaMallocAsync")
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "backend:cudaMallocAsync")
import json
import uuid
import gradio as gr
import spaces
# ZeroGPU startup/build detector anchor. Keep one unconditional module-global
# @spaces.GPU function directly visible in the main app module; production GPU
# callbacks may be owned elsewhere. The detector anchor itself does no work.
@spaces.GPU
def _zerogpu_startup_anchor():
pass
import torch
from diffusers.pipelines.ltx2.utils import (
DISTILLED_SIGMA_VALUES,
LTX2_5_I2V_DEFAULT_SYSTEM_PROMPT,
LTX2_5_T2V_DEFAULT_SYSTEM_PROMPT,
)
from space_config import (
A2V_EXAMPLE_SPECS,
A2V_WIDTH,
A2V_HEIGHT,
A2V_FRAMES,
A2V_ZEROGPU_DURATION_SECONDS,
BUILTIN_LORAS,
HISTORY_LIMIT,
FRAME_RATE,
STANDARD_MAX_SECONDS,
EXPERIMENTAL_MAX_SECONDS,
RESOLUTIONS,
IC_COLORIZER_LORA_REPO_ID,
IC_COLORIZER_LORA_REVISION,
IC_COLORIZER_LORA_WEIGHT_NAME,
IC_COLORIZER_LORA_STRENGTH,
IC_COLORIZER_REFERENCE_DOWNSCALE_FACTOR,
IC_COLORIZER_REFERENCE_STRENGTH,
IC_COLORIZER_CONDITIONING_ATTENTION_STRENGTH,
IC_COLORIZER_EXAMPLE_SPECS,
IC_COLORIZER_DEFAULT_PROFILE,
IC_COLORIZER_PROFILES,
IC_PIXEL_UPSCALER_LORA_REPO_ID,
IC_PIXEL_UPSCALER_LORA_REVISION,
IC_PIXEL_UPSCALER_LORA_WEIGHT_NAME,
IC_PIXEL_UPSCALER_LORA_STRENGTH,
IC_PIXEL_UPSCALER_REFERENCE_DOWNSCALE_FACTOR,
IC_PIXEL_UPSCALER_REFERENCE_STRENGTH,
IC_PIXEL_UPSCALER_CONDITIONING_ATTENTION_STRENGTH,
IC_PIXEL_UPSCALER_MAX_DURATION_SECONDS,
IC_PIXEL_UPSCALER_MAX_OUTPUT_SIDE,
IC_PIXEL_UPSCALER_ZEROGPU_DURATION_SECONDS,
IC_PIXEL_UPSCALER_EXAMPLE_SPECS,
IC_INOUTPAINT_LORA_REPO_ID,
IC_INOUTPAINT_LORA_REVISION,
IC_INOUTPAINT_LORA_WEIGHT_NAME,
IC_INOUTPAINT_LORA_STRENGTH,
IC_INOUTPAINT_REFERENCE_DOWNSCALE_FACTOR,
IC_INOUTPAINT_REFERENCE_STRENGTH,
IC_INOUTPAINT_CONDITIONING_ATTENTION_STRENGTH,
IC_INOUTPAINT_MAX_DURATION_SECONDS,
IC_INOUTPAINT_MAX_OUTPUT_SIDE,
IC_INOUTPAINT_ZEROGPU_DURATION_SECONDS,
IC_INOUTPAINT_EXAMPLE_SPECS,
DEFAULT_PROMPT,
MODEL_QUANTIZATION_POLICY,
MODEL_REPO_ID,
MODEL_RUNTIME_PROFILE,
FULL_SFT_TRANSFORMER_PATH,
FULL_SFT_STAGE2_LORA_WEIGHT_NAME,
MODEL_REVISION,
PROMPT_ENHANCER_REPO_ID,
PROMPT_ENHANCER_REVISION,
PROMPT_TOOL_ZEROGPU_DURATION_SECONDS,
PROMPT_TRANSLATE_LTX_ENGLISH_SYSTEM_PROMPT,
PROMPT_WRITE_FROM_SEED_SYSTEM_PROMPT,
TEXT_ENCODER_OVERRIDE_PATH,
TEXT_ENCODER_OVERRIDE_REPO_ID,
TEXT_ENCODER_OVERRIDE_REVISION,
TRANSFORMER_OVERRIDE_PATH,
TRANSFORMER_OVERRIDE_REPO_ID,
TRANSFORMER_OVERRIDE_REVISION,
)
from ltx import audio_to_video as a2v_backend
from ltx import civitai as civitai_backend
from ltx import generation as generation_backend
from ltx import ic_colorizer as ic_backend
from ltx import ic_pixel_upscaler as pixel_upscaler_backend
from ltx import ic_inoutpaint as inoutpaint_backend
from ltx import hub_search as hub_search_backend
from ltx import lora as lora_backend
from ltx import maintainer_probe as maintainer_probe_backend
from ltx import probe_catalog as maintainer_probe_catalog
from ltx import prompt_tools as prompt_backend
from ltx import research_probe as research_probe_backend
from ltx import probe_artifacts as probe_artifacts
from ltx import runtime as runtime_backend
from ltx import runtime_utils as runtime_utils
from ltx import settings_history as settings_history
from ltx import ui_lora as ui_lora
from ltx import ui_ic_tabs as ui_ic_tabs
from ltx.gradio_policy import INTERNAL_API_VISIBILITY
from ltx.lora_ui_handlers import (
_all_lora_defs,
_invalidate_prepared_loras,
_lora_dropdown,
_sanitize_lora_defs,
add_civitai_session_lora,
add_session_lora,
apply_civitai_example_prompt,
apply_civitai_trigger_words,
apply_hf_full_search_selection,
apply_hub_lora_search_selection,
inspect_civitai_gallery_selection,
inspect_civitai_version_selection,
inspect_hub_lora_repo,
load_civitai_example_prompts,
load_more_civitai_models,
prepare_selected_loras,
remove_selected_session_loras,
resolve_civitai_url,
search_civitai_models,
search_hf_lora_models,
)
from ltx.build_info import CANDIDATE_ID
from ltx.app_config import (
ALLOW_PATTERNS,
ATTENTION_BACKEND,
CANONICAL_MODEL_REPO_ID,
CANONICAL_MODEL_REVISION,
CONFIG_WARNINGS,
EFFECTIVE_A2V_ENABLED,
EFFECTIVE_AUTO_DURATION_ENABLED,
EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
EFFECTIVE_DEFAULT_DURATION_SECONDS,
EFFECTIVE_DEFAULT_LORA_STRENGTH,
EFFECTIVE_DEFAULT_RANDOMIZE_SEED,
EFFECTIVE_DEFAULT_RESOLUTION,
EFFECTIVE_DEFAULT_SEED,
EFFECTIVE_DEFAULT_SELECTED_LORAS,
EFFECTIVE_DEFAULT_USE_AUTO_DURATION,
EFFECTIVE_DEFAULT_USE_DIFFUSION_DECODER,
EFFECTIVE_DIFFUSION_DECODER_ENABLED,
EFFECTIVE_FULL_SFT_STAGE2_LORA_STRENGTH,
EFFECTIVE_IC_COLORIZER_ENABLED,
EFFECTIVE_IC_PIXEL_UPSCALER_ENABLED,
EFFECTIVE_IC_INOUTPAINT_ENABLED,
EFFECTIVE_PROMPT_ENHANCER_ENABLED,
EFFECTIVE_ZEROGPU_GPU_SIZE,
FULL_SFT_STAGE2_ADAPTER_NAME,
FULL_SFT_STAGE2_LORA_REPO_EFFECTIVE,
FULL_SFT_STAGE2_LORA_REVISION_EFFECTIVE,
FULL_SFT_TRANSFORMER_REPO_EFFECTIVE,
FULL_SFT_TRANSFORMER_REVISION_EFFECTIVE,
GPU_CONCURRENCY_ID,
IS_FULL_SFT_PROFILE,
IS_ZEROGPU,
PROMPT_ENHANCER_POLICY,
QUANTIZATION_POLICY,
RUNTIME_PROFILE,
)
from ltx.app_runtime_support import (
APP_LOGGER,
APP_ROOT,
HF_TOKEN,
RUNTIME_A2V_EXAMPLE_DIR,
RUNTIME_IC_EXAMPLE_DIR,
RUNTIME_IC_PIXEL_UPSCALER_EXAMPLE_DIR,
RUNTIME_IC_INOUTPAINT_EXAMPLE_DIR,
SPACE_DEBUG,
WORKER_ROOT,
WORKER_UUID,
cleanup_session_results,
close_request_logger as _close_request_logger,
create_request_paths,
create_session_id,
disk_state as _disk_state,
gpu_state as _gpu_state,
is_uuid_hex as _is_uuid_hex,
normalize_session_id,
open_request_logger as _open_request_logger,
package_identity as _package_identity,
runtime_environment_identity as _runtime_environment_identity,
sha256_file as _sha256_file,
)
from ltx.probe_catalog import (
MAINTAINER_PROBE_CHOICES,
MAINTAINER_PROBE_CURRENT_GATES,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE1,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV_FRAMEWISE,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_LATENT,
MAINTAINER_PROBE_FULL_SFT_30S_UPSAMPLE,
MAINTAINER_PROBE_FULL_SFT_30S_FLF2V_STAGE1,
RESEARCH_PROBE_CHOICES,
)
from ltx.ui_controls import (
bind_custom_resolution_editor as _bind_custom_resolution_editor,
build_custom_resolution_editor as _build_custom_resolution_editor,
build_result_panel as _build_result_panel,
build_seed_controls as _build_seed_controls,
duration_slider_update as _duration_slider_update,
frames_from_seconds as _frames_from_seconds,
load_conditioning_image as _load_conditioning_image,
parse_resolution_value as _parse_resolution_value,
resolution as _resolution,
resolution_duration_controls as _resolution_duration_controls,
resolution_input_preflight as _resolution_input_preflight,
sync_resolution_editor_after as _sync_resolution_editor_after,
supports_experimental_long as _supports_experimental_long,
)
from ltx.conditioning import (
conditioning_mode_status_markdown as _conditioning_mode_status_markdown,
mode_from_condition_images as _mode_from_condition_images,
)
from ltx.zerogpu_duration import (
generation_duration as _duration,
generation_duration_preflight as _generation_duration_preflight,
zerogpu_duration_panel as _zerogpu_duration_panel,
)
from ltx import example_runtime
from ltx.ui_theme import CSS
PIPE = None
PIPE_I2V = None
PIPE_CONDITION = None
PIPE_IC = None
UPSAMPLE_PIPE = None
DIFFUSION_DECODE_PIPE = None
PROMPT_ENHANCER_MODEL = None
PROMPT_ENHANCER_PROCESSOR = None
EXAMPLE_ROWS = []
EXAMPLE_STATE = {"status": "not_prepared", "items": []}
IC_EXAMPLE_ROWS = []
IC_EXAMPLE_STATE = {"status": "not_prepared", "items": []}
PIXEL_UPSCALER_EXAMPLE_ROWS = []
PIXEL_UPSCALER_EXAMPLE_STATE = {"status": "not_prepared", "items": []}
INOUTPAINT_EXAMPLE_ROWS = []
INOUTPAINT_EXAMPLE_STATE = {"status": "not_prepared", "items": []}
A2V_EXAMPLE_ROWS = []
A2V_EXAMPLE_STATE = {"status": "not_prepared", "items": []}
PRELOAD_STATE = {"status": "starting", "candidate_id": CANDIDATE_ID}
RUNTIME_BUILD_POLICY = runtime_backend.RuntimeBuildPolicy(
allow_patterns=tuple(ALLOW_PATTERNS),
runtime_profile=RUNTIME_PROFILE,
is_full_sft_profile=IS_FULL_SFT_PROFILE,
auto_duration_enabled=EFFECTIVE_AUTO_DURATION_ENABLED,
auto_duration_min_seconds=EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
auto_duration_max_seconds=EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
diffusion_decoder_enabled=EFFECTIVE_DIFFUSION_DECODER_ENABLED,
prompt_enhancer_enabled=EFFECTIVE_PROMPT_ENHANCER_ENABLED,
ic_colorizer_enabled=EFFECTIVE_IC_COLORIZER_ENABLED,
ic_pixel_upscaler_enabled=EFFECTIVE_IC_PIXEL_UPSCALER_ENABLED,
ic_inoutpaint_enabled=EFFECTIVE_IC_INOUTPAINT_ENABLED,
transformer_override_repo_id=TRANSFORMER_OVERRIDE_REPO_ID,
transformer_override_path=TRANSFORMER_OVERRIDE_PATH,
transformer_override_revision=TRANSFORMER_OVERRIDE_REVISION,
text_encoder_override_repo_id=TEXT_ENCODER_OVERRIDE_REPO_ID,
text_encoder_override_path=TEXT_ENCODER_OVERRIDE_PATH,
text_encoder_override_revision=TEXT_ENCODER_OVERRIDE_REVISION,
prompt_enhancer_repo_id=PROMPT_ENHANCER_REPO_ID,
prompt_enhancer_revision=PROMPT_ENHANCER_REVISION,
prompt_enhancer_policy=PROMPT_ENHANCER_POLICY,
full_sft_transformer_path=FULL_SFT_TRANSFORMER_PATH,
full_sft_transformer_repo=FULL_SFT_TRANSFORMER_REPO_EFFECTIVE,
full_sft_transformer_revision=FULL_SFT_TRANSFORMER_REVISION_EFFECTIVE,
full_sft_stage2_lora_repo=FULL_SFT_STAGE2_LORA_REPO_EFFECTIVE,
full_sft_stage2_lora_revision=FULL_SFT_STAGE2_LORA_REVISION_EFFECTIVE,
full_sft_stage2_lora_weight_name=FULL_SFT_STAGE2_LORA_WEIGHT_NAME,
full_sft_stage2_lora_strength=EFFECTIVE_FULL_SFT_STAGE2_LORA_STRENGTH,
full_sft_stage2_adapter_name=FULL_SFT_STAGE2_ADAPTER_NAME,
attention_backend=ATTENTION_BACKEND,
)
RUNTIME_PRELOAD_POLICY = runtime_backend.RuntimePreloadPolicy(
candidate_id=CANDIDATE_ID,
model_repo_id=MODEL_REPO_ID,
model_revision=MODEL_REVISION,
model_quantization_policy_requested=MODEL_QUANTIZATION_POLICY,
quantization_policy=QUANTIZATION_POLICY,
model_runtime_profile_requested=MODEL_RUNTIME_PROFILE,
runtime_profile=RUNTIME_PROFILE,
config_warnings=tuple(CONFIG_WARNINGS),
worker_uuid=WORKER_UUID,
canonical_model_repo_id=CANONICAL_MODEL_REPO_ID,
canonical_model_revision=CANONICAL_MODEL_REVISION,
is_full_sft_profile=IS_FULL_SFT_PROFILE,
is_zerogpu=IS_ZEROGPU,
auto_duration_min_seconds=EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
auto_duration_max_seconds=EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
)
def _preload():
global PIPE, PIPE_I2V, PIPE_CONDITION, PIPE_IC, UPSAMPLE_PIPE, DIFFUSION_DECODE_PIPE
global PROMPT_ENHANCER_MODEL, PROMPT_ENHANCER_PROCESSOR, PRELOAD_STATE
outcome = runtime_backend.preload_runtime(
token=HF_TOKEN,
preload_policy=RUNTIME_PRELOAD_POLICY,
build_policy=RUNTIME_BUILD_POLICY,
log_fn=APP_LOGGER.info,
disk_state_fn=_disk_state,
package_identity_fn=_package_identity,
environment_identity_fn=_runtime_environment_identity,
)
if outcome.runtime is not None:
artifacts = outcome.runtime
PIPE = artifacts.pipe
PIPE_I2V = artifacts.pipe_i2v
PIPE_CONDITION = artifacts.pipe_condition
PIPE_IC = artifacts.pipe_ic
UPSAMPLE_PIPE = artifacts.upsample_pipe
DIFFUSION_DECODE_PIPE = artifacts.diffusion_decode_pipe
PROMPT_ENHANCER_MODEL = artifacts.prompt_enhancer_model
PROMPT_ENHANCER_PROCESSOR = artifacts.prompt_enhancer_processor
PRELOAD_STATE = outcome.state
def _runtime_model_status_markdown() -> str:
if PRELOAD_STATE.get("status") != "ready":
error = PRELOAD_STATE.get("error") or "preload is not ready"
base_link = runtime_utils.hf_repo_markdown_link("Lightricks/LTX-2.5-Diffusers")
return (
"**Runtime model: startup failed.** \n"
f"First check access to {base_link}, then confirm the Space Secret `HF_TOKEN` is a read token owned by the **same Hugging Face account** that approved the gated model. Restart the Space after changing access/token. \n"
f"Diagnostic: `{error}`"
)
sources = PRELOAD_STATE.get("model_sources") or {}
base = (sources.get("base") or {}).get("effective") or {}
base_text = runtime_utils.hf_repo_markdown_link(str(base.get('repo_id') or '?')) if base.get('repo_id') else '`?`'
if base.get("revision"):
base_text += f" @ {str(base['revision'])[:12]}…"
base_suffix = " · **fallback active**" if (sources.get("base") or {}).get("fallback") else ""
def component_text(name: str) -> str:
record = sources.get(name) or {}
effective = record.get("effective") or {}
kind = effective.get("kind")
if kind == "disabled":
value = f"Unavailable · {effective.get('reason') or 'disabled'}"
elif kind and kind.startswith("override"):
repo_id = str(effective.get("repo_id") or "?")
value = runtime_utils.hf_repo_markdown_link(repo_id) if repo_id != "?" else "`?`"
if effective.get("path"):
value += f" / {effective['path']}"
quant = effective.get("quantization")
if quant:
value += f" · {quant}"
elif name == "transformer" and kind == "full_sft_base_component":
value = f"Full/SFT · `{effective.get('path', 'transformer_full')}` · {effective.get('quantization', 'NF4')}"
elif name == "diffusion_decoder" and kind == "base_component":
value = "Live PASS · CPU RAM-ready · GPU-lazy · NATTEN · tiled"
elif name == "prompt_enhancer" and kind == "dedicated_gemma4":
value = (
f"Ready in CPU RAM · GPU-lazy · {effective.get('quantization', 'NF4')} · "
+ runtime_utils.hf_repo_markdown_link(effective.get("repo_id"))
)
elif name == "duration_head" and kind == "base_component":
bounds = effective.get("bounds_seconds") or [EFFECTIVE_AUTO_DURATION_MIN_SECONDS, EFFECTIVE_AUTO_DURATION_MAX_SECONDS]
value = f"Ready · model-predicted · {float(bounds[0]):.1f}–{float(bounds[1]):.1f}s clamp · 8k+1 grid"
elif name == "stage2_distilled_lora" and kind == "required_stage2_distilled_lora":
value = "Required · CPU RAM-ready · Stage-2 GPU-lazy · returned to CPU after refinement"
else:
quant = effective.get("quantization") or "base component"
value = f"Default · {quant}"
if record.get("fallback"):
value += " · **requested path failed → fallback/disable**"
return value
defaults = [str(x) for x in EFFECTIVE_DEFAULT_SELECTED_LORAS if str(x).strip()]
lora_text = ", ".join(defaults) if defaults else "None"
return (
f"**Runtime model** · Profile: `{RUNTIME_PROFILE}` · restart-required exclusive · Base: {base_text}{base_suffix} \n"
f"Transformer: {component_text('transformer')} \n"
f"Stage-2 distilled LoRA: {component_text('stage2_distilled_lora')} \n"
f"Text encoder: {component_text('text_encoder')} \n"
f"Diffusion decoder: {component_text('diffusion_decoder')} \n"
f"Prompt enhancer: {component_text('prompt_enhancer')} \n"
f"Auto duration: {component_text('duration_head')} \n"
f"Default LoRA: {lora_text}"
)
def _ic_colorizer_config() -> ic_backend.ColorizerConfig:
return ic_backend.ColorizerConfig(
enabled=EFFECTIVE_IC_COLORIZER_ENABLED,
is_full_sft_profile=IS_FULL_SFT_PROFILE,
runtime_profile=RUNTIME_PROFILE,
frame_rate=FRAME_RATE,
hf_token=HF_TOKEN,
profiles=IC_COLORIZER_PROFILES,
default_profile=IC_COLORIZER_DEFAULT_PROFILE,
example_specs=tuple(IC_COLORIZER_EXAMPLE_SPECS or []),
lora_repo_id=str(IC_COLORIZER_LORA_REPO_ID),
lora_revision=str(IC_COLORIZER_LORA_REVISION or "").strip() or None,
lora_weight_name=str(IC_COLORIZER_LORA_WEIGHT_NAME),
lora_strength=float(IC_COLORIZER_LORA_STRENGTH),
reference_downscale_factor=int(IC_COLORIZER_REFERENCE_DOWNSCALE_FACTOR),
reference_strength=float(IC_COLORIZER_REFERENCE_STRENGTH),
conditioning_attention_strength=float(IC_COLORIZER_CONDITIONING_ATTENTION_STRENGTH),
distilled_sigmas=tuple(float(x) for x in DISTILLED_SIGMA_VALUES),
protected_adapter_name=(FULL_SFT_STAGE2_ADAPTER_NAME if IS_FULL_SFT_PROFILE else None),
)
def _ic_colorizer_runtime() -> ic_backend.ColorizerRuntime:
return ic_backend.ColorizerRuntime(
candidate_id=CANDIDATE_ID,
worker_uuid=WORKER_UUID,
worker_root=WORKER_ROOT,
app_root=APP_ROOT,
example_dir=RUNTIME_IC_EXAMPLE_DIR,
pipe=PIPE,
pipe_ic=PIPE_IC,
preload_state=PRELOAD_STATE,
example_state=IC_EXAMPLE_STATE,
app_logger=APP_LOGGER,
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
gpu_state=_gpu_state,
sha256_file=_sha256_file,
is_uuid_hex=_is_uuid_hex,
)
def _prepare_ic_examples() -> None:
global IC_EXAMPLE_ROWS, IC_EXAMPLE_STATE
IC_EXAMPLE_ROWS, IC_EXAMPLE_STATE = ic_backend.prepare_examples(
_ic_colorizer_config(),
_ic_colorizer_runtime(),
)
PRELOAD_STATE["ic_examples"] = IC_EXAMPLE_STATE
def _ic_example_attribution_markdown() -> str:
return ic_backend.example_attribution_markdown(IC_EXAMPLE_STATE)
def _pixel_upscaler_config() -> pixel_upscaler_backend.PixelUpscalerConfig:
return pixel_upscaler_backend.PixelUpscalerConfig(
enabled=EFFECTIVE_IC_PIXEL_UPSCALER_ENABLED,
runtime_profile=RUNTIME_PROFILE,
frame_rate=FRAME_RATE,
hf_token=HF_TOKEN,
example_specs=tuple(IC_PIXEL_UPSCALER_EXAMPLE_SPECS or []),
lora_repo_id=str(IC_PIXEL_UPSCALER_LORA_REPO_ID),
lora_revision=str(IC_PIXEL_UPSCALER_LORA_REVISION or "").strip() or None,
lora_weight_name=str(IC_PIXEL_UPSCALER_LORA_WEIGHT_NAME),
lora_strength=float(IC_PIXEL_UPSCALER_LORA_STRENGTH),
reference_downscale_factor=int(IC_PIXEL_UPSCALER_REFERENCE_DOWNSCALE_FACTOR),
reference_strength=float(IC_PIXEL_UPSCALER_REFERENCE_STRENGTH),
conditioning_attention_strength=float(IC_PIXEL_UPSCALER_CONDITIONING_ATTENTION_STRENGTH),
max_duration_seconds=float(IC_PIXEL_UPSCALER_MAX_DURATION_SECONDS),
max_output_side=int(IC_PIXEL_UPSCALER_MAX_OUTPUT_SIDE),
zerogpu_duration_seconds=int(IC_PIXEL_UPSCALER_ZEROGPU_DURATION_SECONDS),
)
def _pixel_upscaler_runtime() -> pixel_upscaler_backend.PixelUpscalerRuntime:
return pixel_upscaler_backend.PixelUpscalerRuntime(
candidate_id=CANDIDATE_ID,
worker_uuid=WORKER_UUID,
worker_root=WORKER_ROOT,
app_root=APP_ROOT,
example_dir=RUNTIME_IC_PIXEL_UPSCALER_EXAMPLE_DIR,
pipe_ic=PIPE_IC,
preload_state=PRELOAD_STATE,
example_state=PIXEL_UPSCALER_EXAMPLE_STATE,
app_logger=APP_LOGGER,
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
gpu_state=_gpu_state,
sha256_file=_sha256_file,
is_uuid_hex=_is_uuid_hex,
)
def _prepare_pixel_upscaler_examples() -> None:
global PIXEL_UPSCALER_EXAMPLE_ROWS, PIXEL_UPSCALER_EXAMPLE_STATE
PIXEL_UPSCALER_EXAMPLE_ROWS, PIXEL_UPSCALER_EXAMPLE_STATE = pixel_upscaler_backend.prepare_examples(
_pixel_upscaler_config(),
_pixel_upscaler_runtime(),
)
PRELOAD_STATE["ic_pixel_upscaler_examples"] = PIXEL_UPSCALER_EXAMPLE_STATE
def _pixel_upscaler_example_attribution_markdown() -> str:
return pixel_upscaler_backend.example_attribution_markdown(PIXEL_UPSCALER_EXAMPLE_STATE)
def _inoutpaint_config() -> inoutpaint_backend.InOutpaintConfig:
return inoutpaint_backend.InOutpaintConfig(
enabled=EFFECTIVE_IC_INOUTPAINT_ENABLED,
runtime_profile=RUNTIME_PROFILE,
frame_rate=FRAME_RATE,
hf_token=HF_TOKEN,
example_specs=tuple(IC_INOUTPAINT_EXAMPLE_SPECS or []),
lora_repo_id=str(IC_INOUTPAINT_LORA_REPO_ID),
lora_revision=str(IC_INOUTPAINT_LORA_REVISION or "").strip() or None,
lora_weight_name=str(IC_INOUTPAINT_LORA_WEIGHT_NAME),
lora_strength=float(IC_INOUTPAINT_LORA_STRENGTH),
reference_downscale_factor=int(IC_INOUTPAINT_REFERENCE_DOWNSCALE_FACTOR),
reference_strength=float(IC_INOUTPAINT_REFERENCE_STRENGTH),
conditioning_attention_strength=float(IC_INOUTPAINT_CONDITIONING_ATTENTION_STRENGTH),
max_duration_seconds=float(IC_INOUTPAINT_MAX_DURATION_SECONDS),
max_output_side=int(IC_INOUTPAINT_MAX_OUTPUT_SIDE),
zerogpu_duration_seconds=int(IC_INOUTPAINT_ZEROGPU_DURATION_SECONDS),
)
def _inoutpaint_runtime() -> inoutpaint_backend.InOutpaintRuntime:
return inoutpaint_backend.InOutpaintRuntime(
candidate_id=CANDIDATE_ID,
worker_uuid=WORKER_UUID,
worker_root=WORKER_ROOT,
app_root=APP_ROOT,
example_dir=RUNTIME_IC_INOUTPAINT_EXAMPLE_DIR,
pipe_ic=PIPE_IC,
preload_state=PRELOAD_STATE,
example_state=INOUTPAINT_EXAMPLE_STATE,
app_logger=APP_LOGGER,
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
gpu_state=_gpu_state,
sha256_file=_sha256_file,
is_uuid_hex=_is_uuid_hex,
)
def _prepare_inoutpaint_examples() -> None:
global INOUTPAINT_EXAMPLE_ROWS, INOUTPAINT_EXAMPLE_STATE
INOUTPAINT_EXAMPLE_ROWS, INOUTPAINT_EXAMPLE_STATE = inoutpaint_backend.prepare_examples(
_inoutpaint_config(), _inoutpaint_runtime()
)
PRELOAD_STATE["ic_inoutpaint_examples"] = INOUTPAINT_EXAMPLE_STATE
def _inoutpaint_example_attribution_markdown() -> str:
return inoutpaint_backend.example_attribution_markdown(INOUTPAINT_EXAMPLE_STATE)
_preload()
EXAMPLE_ROWS, EXAMPLE_STATE = example_runtime.prepare_examples()
PRELOAD_STATE["examples"] = EXAMPLE_STATE
_prepare_ic_examples()
_prepare_pixel_upscaler_examples()
_prepare_inoutpaint_examples()
def _lora_adapter_state() -> dict:
return lora_backend.adapter_state(PIPE)
def _load_request_loras(selected, custom_loras, prepared_loras, strength: float, request_id: str) -> tuple[list[dict], dict]:
try:
return lora_backend.load_request_loras(
pipe=PIPE,
pipe_i2v=PIPE_I2V,
pipe_condition=PIPE_CONDITION,
pipe_ic=PIPE_IC,
selected=selected,
builtin_loras=BUILTIN_LORAS,
custom_loras=custom_loras,
prepared_loras=prepared_loras,
strength=strength,
request_id=request_id,
gpu_state=_gpu_state,
)
except lora_backend.LoraSelectionError as exc:
raise gr.Error(str(exc)) from exc
def _cleanup_request_loras(loaded, metrics=None) -> dict:
return lora_backend.cleanup_request_loras(
pipe=PIPE,
loaded=loaded,
metrics=metrics,
full_sft_profile=IS_FULL_SFT_PROFILE,
gpu_state=_gpu_state,
)
def _settings_snapshot(
prompt, duration_seconds, experimental_long, resolution_key, seed, randomize_seed,
selected_loras, lora_strength, custom_loras, use_diffusion_decoder=False, use_auto_duration=False,
start_image_path=None, middle_image_path=None, end_image_path=None,
) -> dict:
return settings_history.settings_snapshot(
prompt, duration_seconds, experimental_long, resolution_key, seed, randomize_seed,
selected_loras, lora_strength, custom_loras, use_diffusion_decoder, use_auto_duration,
start_image_path, middle_image_path, end_image_path,
mode=_mode_from_condition_images(start_image_path, middle_image_path, end_image_path),
candidate_id=CANDIDATE_ID,
runtime_profile=RUNTIME_PROFILE,
model_repo_id=MODEL_REPO_ID,
model_revision=MODEL_REVISION,
model_quantization_policy=MODEL_QUANTIZATION_POLICY,
auto_duration_min_seconds=EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
auto_duration_max_seconds=EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
preload_state=PRELOAD_STATE,
sanitize_lora_defs=_sanitize_lora_defs,
)
def _write_settings_export(
prompt, duration_seconds, experimental_long, resolution_key, seed, randomize_seed, selected_loras,
lora_strength, custom_loras, use_diffusion_decoder, use_auto_duration, start_image_path, middle_image_path, end_image_path, session_id,
):
session_id = normalize_session_id(session_id)
path = WORKER_ROOT / session_id / "settings_exports" / f"ltx25_settings_{uuid.uuid4().hex}.json"
payload = _settings_snapshot(
prompt, duration_seconds, experimental_long, resolution_key, seed, randomize_seed,
selected_loras, lora_strength, custom_loras, use_diffusion_decoder, use_auto_duration, start_image_path, middle_image_path, end_image_path,
)
return settings_history.write_settings_export(path, payload)
def _apply_settings_payload(
payload, import_prompt, import_generation, import_seed, import_lora, import_session_loras,
current_prompt, current_duration, current_experimental, current_resolution, current_seed,
current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
):
return settings_history.apply_settings_payload(
payload, import_prompt, import_generation, import_seed, import_lora, import_session_loras,
current_prompt, current_duration, current_experimental, current_resolution, current_seed,
current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
experimental_max_seconds=EXPERIMENTAL_MAX_SECONDS,
standard_max_seconds=STANDARD_MAX_SECONDS,
auto_duration_min_seconds=EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
auto_duration_max_seconds=EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
diffusion_decoder_available=DIFFUSION_DECODE_PIPE is not None,
auto_duration_available=bool(getattr(PIPE, "duration_head", None) is not None),
parse_resolution_value=_parse_resolution_value,
supports_experimental_long=_supports_experimental_long,
duration_slider_update=_duration_slider_update,
sanitize_lora_defs=_sanitize_lora_defs,
all_lora_defs=_all_lora_defs,
lora_dropdown=_lora_dropdown,
)
def _import_settings(
settings_file, import_prompt, import_generation, import_seed, import_lora, import_session_loras,
current_prompt, current_duration, current_experimental, current_resolution, current_seed,
current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
):
payload = settings_history.read_settings_payload(settings_file)
values, warnings = _apply_settings_payload(
payload, import_prompt, import_generation, import_seed, import_lora, import_session_loras,
current_prompt, current_duration, current_experimental, current_resolution, current_seed,
current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
)
provenance = payload.get("runtime_provenance") or {}
requested = provenance.get("requested_model") or {}
note = (
"Applied selected portable settings. Runtime provenance/model override fields are read-only and were not imported. "
f"Source build: `{payload.get('candidate_id', '?')}`; source model: {runtime_utils.hf_repo_markdown_link(requested.get('repo_id'))}."
+ settings_history.warning_note(warnings)
)
return (*values, note)
def _history_label(record: dict) -> str:
return settings_history.history_label(record)
def _history_outputs(history) -> tuple:
return settings_history.history_outputs(history)
def _append_probe_output(existing, probe_path):
values = probe_artifacts.append_probe_path(
existing, probe_path, limit=max(12, int(HISTORY_LIMIT) * 3)
)
return values, values
def _refresh_latest_probe_output(existing, session_id):
found = probe_artifacts.list_session_probe_paths(WORKER_ROOT, normalize_session_id(session_id))
values = list(existing or [])
if found:
values = probe_artifacts.append_probe_path(
values, found[-1], limit=max(12, int(HISTORY_LIMIT) * 3)
)
return values, values
def _clear_generation_result():
return None, ""
def _update_history(history, record: dict) -> list[dict]:
return settings_history.update_history(history, record, history_limit=HISTORY_LIMIT)
def _restore_history_settings(
history, selected_history, current_prompt, current_duration, current_experimental, current_resolution,
current_seed, current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
):
history = list(history or [])
match = next((item for item in history if _history_label(item) == selected_history), None)
if match is None:
raise gr.Error("Choose a recent run first.")
payload = match.get("settings") or {}
values, warnings = _apply_settings_payload(
payload, True, True, True, True, True,
current_prompt, current_duration, current_experimental, current_resolution, current_seed,
current_randomize, current_selected_loras, current_lora_strength, current_custom_loras, current_use_diffusion_decoder,
current_use_auto_duration,
)
note = (
f"Restored settings from run `{match.get('request_id')}`. Input images are not restored."
+ settings_history.warning_note(warnings)
)
return (*values, note)
def _maintainer_gate_markdown() -> str:
gate_count = len(MAINTAINER_PROBE_CURRENT_GATES)
if gate_count == 0:
return "**Current maintainer gate: 0.** No Probe is required for promotion right now. Optional profiles may still be used for diagnostics."
runtime_note = ""
if not IS_FULL_SFT_PROFILE:
runtime_note = " \n⚠️ This gate requires the `full_sft_nf4` runtime profile; switch profile and restart before running it."
return (
f"**Current maintainer gate: {gate_count}.** Run the preselected profile below to close the current gate. "
"Other Probe profiles remain optional diagnostics and do not become promotion requirements merely by existing."
f"{runtime_note}"
)
def _maintainer_probe_profile_description(profile_id) -> str:
return maintainer_probe_catalog.profile_description(profile_id)
def _maintainer_probe_profile_ui(profile_id):
selected = str(profile_id or "")
supported = selected in {
MAINTAINER_PROBE_FULL_SFT_30S_FLF2V_STAGE1,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV_FRAMEWISE,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_LATENT,
MAINTAINER_PROBE_FULL_SFT_30S_UPSAMPLE,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE1,
}
if selected == MAINTAINER_PROBE_FULL_SFT_30S_FLF2V_STAGE1:
backend_ready = PIPE_CONDITION is not None
else:
backend_ready = PIPE_I2V is not None and UPSAMPLE_PIPE is not None
if selected == MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION:
backend_ready = backend_ready and DIFFUSION_DECODE_PIPE is not None
runnable = supported and IS_FULL_SFT_PROFILE and backend_ready
return _maintainer_probe_profile_description(selected), gr.Button(value="Run Probe", variant="primary", interactive=bool(runnable))
def _maintainer_probe_duration(profile_id, session_id, progress=None):
del session_id, progress
selected = str(profile_id or "")
durations = {
MAINTAINER_PROBE_FULL_SFT_30S_FLF2V_STAGE1: maintainer_probe_backend.FULL_SFT_30S_FLF2V_STAGE1_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION: maintainer_probe_backend.FULL_SFT_30S_STAGE2_DIFFUSION_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV: maintainer_probe_backend.FULL_SFT_30S_STAGE2_CONV_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV_FRAMEWISE: maintainer_probe_backend.FULL_SFT_30S_STAGE2_CONV_FRAMEWISE_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_LATENT: maintainer_probe_backend.FULL_SFT_30S_STAGE2_LATENT_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_UPSAMPLE: maintainer_probe_backend.FULL_SFT_30S_UPSAMPLE_ZEROGPU_DURATION_SECONDS,
MAINTAINER_PROBE_FULL_SFT_30S_STAGE1: maintainer_probe_backend.FULL_SFT_30S_STAGE1_ZEROGPU_DURATION_SECONDS,
}
return int(durations.get(selected, 5))
def _maintainer_probe_cats_example() -> tuple[str, str]:
items = list((EXAMPLE_STATE or {}).get("items") or [])
for row, item in zip(EXAMPLE_ROWS, items):
if str(item.get("label") or "") == "Cats · I2V" and row and row[0] and len(row) >= 3:
return str(row[0]), str(row[2])
raise gr.Error("Probe requires the startup Cats · I2V example, but it is unavailable on this worker.")
def _maintainer_probe_flf2v_example() -> tuple[str, str, str]:
items = list((EXAMPLE_STATE or {}).get("items") or [])
for row, item in zip(EXAMPLE_ROWS, items):
if str(item.get("label") or "") == "Blue bird · first + last frame" and row and len(row) >= 3 and row[0] and row[1]:
return str(row[0]), str(row[1]), str(row[2])
raise gr.Error("Probe requires the startup Blue bird · first + last frame example, but it is unavailable on this worker.")
def _run_maintainer_backend(profile_id, session_id, progress):
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_FLF2V_STAGE1:
return maintainer_probe_backend.run_full_sft_30s_flf2v_stage1_scout(
session_id=session_id,
progress=progress,
candidate_id=CANDIDATE_ID,
runtime=_generation_runtime(),
hooks=_generation_hooks(),
flf2v_example=_maintainer_probe_flf2v_example(),
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
)
common = dict(
session_id=session_id,
progress=progress,
candidate_id=CANDIDATE_ID,
runtime=_generation_runtime(),
hooks=_generation_hooks(),
cats_example=_maintainer_probe_cats_example(),
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION:
return maintainer_probe_backend.run_full_sft_30s_stage2_diffusion_scout(**common)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV:
return maintainer_probe_backend.run_full_sft_30s_stage2_conv_scout(**common)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_CONV_FRAMEWISE:
return maintainer_probe_backend.run_full_sft_30s_stage2_conv_framewise_scout(**common)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_LATENT:
return maintainer_probe_backend.run_full_sft_30s_stage2_latent_scout(**common)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_UPSAMPLE:
return maintainer_probe_backend.run_full_sft_30s_upsample_scout(**common)
if profile_id == MAINTAINER_PROBE_FULL_SFT_30S_STAGE1:
return maintainer_probe_backend.run_full_sft_30s_stage1_scout(**common)
raise gr.Error("Select a supported Maintainer Probe profile first.")
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_maintainer_probe_duration)
def run_maintainer_probe(profile_id, session_id, progress=gr.Progress(track_tqdm=False)):
return _run_maintainer_backend(str(profile_id or ""), session_id, progress)
def _research_probe_profile_description(profile_id) -> str:
selected = str(profile_id or "")
spec = research_probe_backend.RESEARCH_PROFILE_SPECS.get(selected)
if spec is None:
return (
"**Gate-free Research Probe.** Choose any profile whenever useful. Research failures are evidence, not promotion failures; "
"shared-runtime profiles remain serial until isolation is proven."
)
return (
"**RESEARCH · gate-free · aggressive exploration** \n"
f"{spec['label']} \n"
f"Fixed contract: Full/SFT · I2V · Cats · 512×512 · **{spec['frames']}f · {spec['steps']} Stage-1 steps** · seed 42 · no user LoRA · latent output only. "
f"Reservation: **{spec['duration']}s**. Timing is optional; run whenever the information is useful."
)
def _research_probe_profile_ui(profile_id):
selected = str(profile_id or "")
runnable = selected in research_probe_backend.RESEARCH_PROFILE_SPECS and IS_FULL_SFT_PROFILE and PIPE_I2V is not None
return _research_probe_profile_description(selected), gr.Button(
value="Run Research Probe", variant="secondary", interactive=bool(runnable)
)
def _research_probe_duration(profile_id, session_id, progress=None):
del session_id, progress
spec = research_probe_backend.RESEARCH_PROFILE_SPECS.get(str(profile_id or ""))
return int(spec['duration']) if spec else 5
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_research_probe_duration)
def run_research_probe(profile_id, session_id, progress=gr.Progress(track_tqdm=False)):
return research_probe_backend.run_research_probe(
str(profile_id or ""),
session_id=session_id,
progress=progress,
candidate_id=CANDIDATE_ID,
runtime=_generation_runtime(),
hooks=_generation_hooks(),
cats_example=_maintainer_probe_cats_example(),
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
)
def _generation_runtime() -> generation_backend.GenerationRuntime:
return generation_backend.GenerationRuntime(
candidate_id=CANDIDATE_ID,
diffusion_decode_pipe=DIFFUSION_DECODE_PIPE,
auto_duration_enabled=EFFECTIVE_AUTO_DURATION_ENABLED,
auto_duration_max_seconds=EFFECTIVE_AUTO_DURATION_MAX_SECONDS,
auto_duration_min_seconds=EFFECTIVE_AUTO_DURATION_MIN_SECONDS,
full_sft_stage2_lora_strength=EFFECTIVE_FULL_SFT_STAGE2_LORA_STRENGTH,
experimental_max_seconds=EXPERIMENTAL_MAX_SECONDS,
frame_rate=FRAME_RATE,
full_sft_stage2_adapter_name=FULL_SFT_STAGE2_ADAPTER_NAME,
is_full_sft_profile=IS_FULL_SFT_PROFILE,
pipe=PIPE,
pipe_condition=PIPE_CONDITION,
pipe_i2v=PIPE_I2V,
preload_state=PRELOAD_STATE,
runtime_profile=RUNTIME_PROFILE,
standard_max_seconds=STANDARD_MAX_SECONDS,
upsample_pipe=UPSAMPLE_PIPE,
worker_uuid=WORKER_UUID,
)
def _generation_hooks() -> generation_backend.GenerationHooks:
return generation_backend.GenerationHooks(
cleanup_request_loras=_cleanup_request_loras,
close_request_logger=_close_request_logger,
disk_state=_disk_state,
duration=_duration,
frames_from_seconds=_frames_from_seconds,
gpu_state=_gpu_state,
history_outputs=_history_outputs,
load_conditioning_image=_load_conditioning_image,
load_request_loras=_load_request_loras,
lora_adapter_state=_lora_adapter_state,
mode_from_images=_mode_from_condition_images,
open_request_logger=_open_request_logger,
resolution=_resolution,
settings_snapshot=_settings_snapshot,
sha256_file=_sha256_file,
supports_experimental_long=_supports_experimental_long,
update_history=_update_history,
create_request_paths=create_request_paths,
)
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_duration)
def generate(
prompt,
start_image_path,
middle_image_path,
end_image_path,
duration_seconds,
experimental_long,
resolution_key,
seed,
randomize_seed,
selected_loras,
lora_strength,
custom_loras,
prepared_loras,
use_diffusion_decoder,
use_auto_duration,
session_id,
history,
progress=gr.Progress(track_tqdm=True),
):
return generation_backend.run(
prompt, start_image_path, middle_image_path, end_image_path, duration_seconds, experimental_long, resolution_key,
seed, randomize_seed, selected_loras, lora_strength, custom_loras, prepared_loras,
use_diffusion_decoder, use_auto_duration, session_id, history, progress,
runtime=_generation_runtime(),
hooks=_generation_hooks(),
)
def _run_prompt_tool_separate(
tool: str,
prompt,
start_image_path,
middle_image_path,
end_image_path,
session_id,
manual_system_prompt=None,
):
global PROMPT_ENHANCER_MODEL, PROMPT_ENHANCER_PROCESSOR
session_id = normalize_session_id(session_id)
request_id = uuid.uuid4().hex
mode = _mode_from_condition_images(start_image_path, middle_image_path, end_image_path)
model_source = ((PRELOAD_STATE.get("model_sources") or {}).get("prompt_enhancer") or {})
output, status_text, result, disable_global_model = prompt_backend.run(
tool=tool,
prompt=prompt,
start_image_path=start_image_path,
end_image_path=end_image_path,
session_id=session_id,
request_id=request_id,
candidate_id=CANDIDATE_ID,
worker_uuid=WORKER_UUID,
mode=mode,
pipe=PIPE,
model=PROMPT_ENHANCER_MODEL,
processor=PROMPT_ENHANCER_PROCESSOR,
runtime_ready=(PRELOAD_STATE.get("status") == "ready"),
model_source=model_source,
gpu_state=_gpu_state,
sha256_file=_sha256_file,
official_t2v_system_prompt=LTX2_5_T2V_DEFAULT_SYSTEM_PROMPT,
official_i2v_system_prompt=LTX2_5_I2V_DEFAULT_SYSTEM_PROMPT,
translate_system_prompt=PROMPT_TRANSLATE_LTX_ENGLISH_SYSTEM_PROMPT,
write_system_prompt=PROMPT_WRITE_FROM_SEED_SYSTEM_PROMPT,
manual_system_prompt=manual_system_prompt,
requested_duration_seconds=PROMPT_TOOL_ZEROGPU_DURATION_SECONDS,
)
if disable_global_model:
PROMPT_ENHANCER_MODEL = None
PROMPT_ENHANCER_PROCESSOR = None
APP_LOGGER.info("[D1R8P30R0] prompt_tools " + json.dumps(result, sort_keys=True))
return output, status_text
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=PROMPT_TOOL_ZEROGPU_DURATION_SECONDS)
def enhance_prompt_separate(prompt, start_image_path, middle_image_path, end_image_path, session_id):
return _run_prompt_tool_separate(
prompt_backend.TOOL_ENHANCE, prompt, start_image_path, middle_image_path, end_image_path, session_id
)
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=PROMPT_TOOL_ZEROGPU_DURATION_SECONDS)
def translate_prompt_separate(prompt, manual_enabled, manual_system_prompt, session_id):
return _run_prompt_tool_separate(
prompt_backend.TOOL_TRANSLATE,
prompt,
None,
None,
None,
session_id,
manual_system_prompt if manual_enabled else None,
)
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=PROMPT_TOOL_ZEROGPU_DURATION_SECONDS)
def write_prompt_from_seed_separate(prompt, manual_enabled, manual_system_prompt, session_id):
return _run_prompt_tool_separate(
prompt_backend.TOOL_WRITE,
prompt,
None,
None,
None,
session_id,
manual_system_prompt if manual_enabled else None,
)
def _audio_to_video_config() -> a2v_backend.AudioToVideoConfig:
audio_vae = getattr(PIPE_I2V, "audio_vae", None) or getattr(PIPE, "audio_vae", None)
audio_config = getattr(audio_vae, "config", None)
sample_rate = int(getattr(audio_config, "sample_rate", 16000))
hop_length = int(getattr(audio_config, "mel_hop_length", 160))
mel_bins = int(getattr(audio_config, "mel_bins", 64))
compression = int(
getattr(
PIPE_I2V,
"audio_vae_temporal_compression_ratio",
getattr(audio_vae, "temporal_compression_ratio", 4),
)
or 4
)
return a2v_backend.AudioToVideoConfig(
enabled=EFFECTIVE_A2V_ENABLED,
is_full_sft_profile=IS_FULL_SFT_PROFILE,
frame_rate=FRAME_RATE,
width=int(A2V_WIDTH),
height=int(A2V_HEIGHT),
num_frames=int(A2V_FRAMES),
zerogpu_duration_seconds=int(A2V_ZEROGPU_DURATION_SECONDS),
audio_sample_rate=sample_rate,
audio_hop_length=hop_length,
audio_mel_bins=mel_bins,
audio_compression_ratio=compression,
example_specs=tuple(A2V_EXAMPLE_SPECS or []),
)
def _audio_to_video_runtime() -> a2v_backend.AudioToVideoRuntime:
return a2v_backend.AudioToVideoRuntime(
candidate_id=CANDIDATE_ID,
worker_uuid=WORKER_UUID,
worker_root=WORKER_ROOT,
pipe=PIPE,
pipe_i2v=PIPE_I2V,
upsample_pipe=UPSAMPLE_PIPE,
preload_state=PRELOAD_STATE,
full_sft_stage2_adapter_name=FULL_SFT_STAGE2_ADAPTER_NAME,
full_sft_stage2_lora_strength=EFFECTIVE_FULL_SFT_STAGE2_LORA_STRENGTH,
create_request_paths=create_request_paths,
open_request_logger=_open_request_logger,
close_request_logger=_close_request_logger,
load_conditioning_image=_load_conditioning_image,
gpu_state=_gpu_state,
sha256_file=_sha256_file,
lora_adapter_state=_lora_adapter_state,
normalize_session_id=normalize_session_id,
example_dir=RUNTIME_A2V_EXAMPLE_DIR,
app_logger=APP_LOGGER,
hf_token=HF_TOKEN,
resolved_revision_from_hub_path=runtime_utils.resolved_revision_from_hub_path,
)
def _prepare_a2v_examples() -> None:
global A2V_EXAMPLE_ROWS, A2V_EXAMPLE_STATE
A2V_EXAMPLE_ROWS, A2V_EXAMPLE_STATE = a2v_backend.prepare_examples(
_audio_to_video_config(),
_audio_to_video_runtime(),
)
PRELOAD_STATE["a2v_examples"] = A2V_EXAMPLE_STATE
# A2V example localization depends on the helpers above being bound at module startup.
_prepare_a2v_examples()
def prepare_audio_to_video(audio_value, image_value, prompt, seed, randomize_seed, session_id):
return a2v_backend.prepare(
audio_value,
image_value,
prompt,
seed,
randomize_seed,
session_id,
config=_audio_to_video_config(),
runtime=_audio_to_video_runtime(),
)
def _audio_to_video_duration(prepared, session_id, *args): # noqa: ARG001
return a2v_backend.duration(
prepared,
session_id,
default_seconds=int(A2V_ZEROGPU_DURATION_SECONDS),
)
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_audio_to_video_duration)
def generate_audio_to_video(prepared, session_id, progress=gr.Progress(track_tqdm=False)):
return a2v_backend.generate(
prepared,
session_id,
progress,
config=_audio_to_video_config(),
runtime=_audio_to_video_runtime(),
)
def prepare_ic_colorizer(video, prompt, profile_key, seed, randomize_seed, session_id):
return ic_backend.prepare(
video,
prompt,
profile_key,
seed,
randomize_seed,
session_id,
config=_ic_colorizer_config(),
runtime=_ic_colorizer_runtime(),
)
def _ic_colorizer_duration(prepared, session_id, *args): # noqa: ARG001
return ic_backend.duration(prepared, config=_ic_colorizer_config())
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_ic_colorizer_duration)
def generate_ic_colorizer(prepared, session_id, progress=gr.Progress(track_tqdm=False)):
return ic_backend.generate(
prepared,
session_id,
progress,
config=_ic_colorizer_config(),
runtime=_ic_colorizer_runtime(),
)
def prepare_pixel_upscaler(video, prompt, seed, randomize_seed, session_id):
return pixel_upscaler_backend.prepare(
video,
prompt,
seed,
randomize_seed,
session_id,
config=_pixel_upscaler_config(),
runtime=_pixel_upscaler_runtime(),
)
def _pixel_upscaler_duration(prepared, session_id, *args): # noqa: ARG001
return pixel_upscaler_backend.duration(prepared, config=_pixel_upscaler_config())
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_pixel_upscaler_duration)
def generate_pixel_upscaler(prepared, session_id, progress=gr.Progress(track_tqdm=False)):
return pixel_upscaler_backend.generate(
prepared,
session_id,
progress,
config=_pixel_upscaler_config(),
runtime=_pixel_upscaler_runtime(),
)
def prepare_inoutpaint(video, mask, prompt, mode, layout, dilation_px, seed, randomize_seed, session_id):
return inoutpaint_backend.prepare(
video, mask, prompt, mode, layout, dilation_px, seed, randomize_seed, session_id,
config=_inoutpaint_config(), runtime=_inoutpaint_runtime(),
)
def _inoutpaint_duration(prepared, session_id, *args): # noqa: ARG001
return inoutpaint_backend.duration(prepared, config=_inoutpaint_config())
@spaces.GPU(size=EFFECTIVE_ZEROGPU_GPU_SIZE, duration=_inoutpaint_duration)
def generate_inoutpaint(prepared, session_id, progress=gr.Progress(track_tqdm=False)):
return inoutpaint_backend.generate(
prepared, session_id, progress, config=_inoutpaint_config(), runtime=_inoutpaint_runtime(),
)
with gr.Blocks(title="LTX-2.5 Video", delete_cache=(3600, 10800)) as demo:
session_id_state = gr.State(value=create_session_id, delete_callback=cleanup_session_results)
custom_lora_state = gr.State(value=lambda: [])
prepared_lora_state = gr.State(value=lambda: [])
history_state = gr.State(value=lambda: [])
probe_files_state = gr.State(value=lambda: [])
latest_probe_state = gr.State(value=None)
maintainer_probe_files_state = gr.State(value=lambda: [])
maintainer_latest_probe_state = gr.State(value=None)
research_probe_files_state = gr.State(value=lambda: [])
research_latest_probe_state = gr.State(value=None)
a2v_prepared_state = gr.State(value=lambda: {})
a2v_probe_files_state = gr.State(value=lambda: [])
a2v_latest_probe_state = gr.State(value=None)
ic_prepared_state = gr.State(value=lambda: {})
ic_probe_files_state = gr.State(value=lambda: [])
ic_latest_probe_state = gr.State(value=None)
pixel_upscaler_prepared_state = gr.State(value=lambda: {})
pixel_upscaler_probe_files_state = gr.State(value=lambda: [])
pixel_upscaler_latest_probe_state = gr.State(value=None)
inoutpaint_prepared_state = gr.State(value=lambda: {})
inoutpaint_probe_files_state = gr.State(value=lambda: [])
inoutpaint_latest_probe_state = gr.State(value=None)
hero_runtime = (
"Full/SFT guided Stage 1 + distilled-LoRA Stage 2 · synchronized audio · 48GB-oriented runtime"
if IS_FULL_SFT_PROFILE
else "Distilled two-stage generation · synchronized audio · 48GB-oriented runtime"
)
gr.HTML(
f'<div id="ltx-hero"><h1>LTX-2.5 Video</h1><p>{hero_runtime}</p></div>'
)
if IS_FULL_SFT_PROFILE:
gr.Markdown(
"**Runtime profile: Full / SFT · restart-required exclusive.** Stage 1 uses the NF4 full transformer "
"with 30-step CFG/STG guidance. User LoRAs use the same picker as distilled mode: they apply in Stage 1 "
"and remain active in Stage 2, where the internal distilled adapter is added automatically. The internal "
"adapter source/strength is configured only in `space_config.py`; switching profiles requires a restart."
)
gr.Markdown(_runtime_model_status_markdown(), elem_id="runtime-model-status")
with gr.Tabs():
with gr.Tab("Generate"):
with gr.Row(equal_height=False):
with gr.Column(scale=6):
prompt_tools_ready = bool(
PROMPT_ENHANCER_MODEL is not None and PROMPT_ENHANCER_PROCESSOR is not None
)
with gr.Group():
prompt = gr.Textbox(
label="Prompt",
lines=4,
value=DEFAULT_PROMPT,
)
with gr.Row(equal_height=True):
enhance_prompt_btn = gr.Button(
"Enhance Prompt",
variant="secondary",
interactive=prompt_tools_ready,
)
translate_prompt_btn = gr.Button(
"Translate → LTX English",
variant="secondary",
interactive=prompt_tools_ready,
)
write_prompt_btn = gr.Button(
"Write from Seed",
variant="secondary",
interactive=prompt_tools_ready,
)
prompt_tools_status = gr.Markdown()
with gr.Accordion("Prompt Tools · advanced", open=False):
gr.Markdown(
"All three actions reuse the same dedicated Gemma 4 runtime and replace the Prompt textbox only after a successful result. "
"**Enhance Prompt** keeps the official LTX-2.5 prompt-enhancement contract; for any image-conditioned mode it uses the Start image only. "
"**Translate** and **Write from Seed** are text-only. Their full system prompts can be overridden below without changing Enhance Prompt."
)
translate_manual_enabled = gr.Checkbox(
False, label="Translate · use full manual system prompt"
)
translate_manual_prompt = gr.Textbox(
label="Translate · full system prompt",
value=PROMPT_TRANSLATE_LTX_ENGLISH_SYSTEM_PROMPT,
lines=8,
)
write_manual_enabled = gr.Checkbox(
False, label="Write from Seed · use full manual system prompt"
)
write_manual_prompt = gr.Textbox(
label="Write from Seed · full system prompt",
value=PROMPT_WRITE_FROM_SEED_SYSTEM_PROMPT,
lines=8,
)
with gr.Accordion("Image conditioning / keyframes · optional", open=False):
with gr.Row(equal_height=True):
image = gr.Image(
label="Start image · optional",
type="filepath",
sources=["upload", "clipboard"],
height=250,
)
middle_image = gr.Image(
label="Middle image · optional · experimental keyframe",
type="filepath",
sources=["upload", "clipboard"],
height=250,
)
end_image = gr.Image(
label="End image · optional · experimental FLF2V",
type="filepath",
sources=["upload", "clipboard"],
height=250,
)
gr.Markdown(
"No image → **T2V** · Start only → **I2V** · Start + End → **experimental FLF2V** · "
"Start + Middle (optionally + End) → **experimental timeline keyframe**. "
"Middle is snapped to the nearest model-latent midpoint; Middle/End without Start is rejected.",
elem_classes=["ltx-subtle"],
)
conditioning_mode_status = gr.Markdown(
_conditioning_mode_status_markdown(None, None, None),
elem_classes=["ltx-subtle"],
)
with gr.Row():
duration_seconds = gr.Slider(
minimum=1.0,
maximum=STANDARD_MAX_SECONDS,
step=0.5,
value=min(STANDARD_MAX_SECONDS, max(1.0, EFFECTIVE_DEFAULT_DURATION_SECONDS)),
label="Duration",
info=(
"1–15s standard; 15–30s experimental at 512×512 only. "
"Rounded to the required 8k+1 frame grid at 24 fps."
),
)
resolution = gr.Dropdown(
choices=list(RESOLUTIONS.keys()),
value=EFFECTIVE_DEFAULT_RESOLUTION,
label="Resolution",
allow_custom_value=True,
info="Choose a preset, or use Custom resolution below. Direct WIDTH × HEIGHT entry also remains supported; both dimensions must be multiples of 64.",
)
custom_resolution_width, custom_resolution_height, apply_custom_resolution_btn, custom_resolution_status = (
_build_custom_resolution_editor(EFFECTIVE_DEFAULT_RESOLUTION)
)
duration_options_label = "Duration / ZeroGPU quota" if IS_ZEROGPU else "Duration options"
with gr.Accordion(duration_options_label, open=False):
experimental_long = gr.Checkbox(
value=False,
interactive=_supports_experimental_long(EFFECTIVE_DEFAULT_RESOLUTION),
label="Experimental long duration (>15s)",
info="Allows 15–30s only at 512×512. The 30s / 721f endpoint is live-passed for distilled T2V and I2V.",
)
use_auto_duration = gr.Checkbox(
value=EFFECTIVE_DEFAULT_USE_AUTO_DURATION,
interactive=bool(getattr(PIPE, "duration_head", None) is not None),
label="Auto duration · experimental",
info=(
f"Let the LTX-2.5 duration head choose the shot length within "
f"{EFFECTIVE_AUTO_DURATION_MIN_SECONDS:.1f}–{EFFECTIVE_AUTO_DURATION_MAX_SECONDS:.1f}s. "
"The manual Duration slider is ignored while enabled."
),
)
gr.Markdown(
"Long duration is explicit opt-in. Full/SFT is limited here to the tested 121f / 5s range at 512×512; Distilled is the recommended deployment profile. Auto Duration stays within its supported range.",
elem_classes=["ltx-subtle"],
)
if IS_ZEROGPU:
gr.Markdown(
"ZeroGPU checks requested duration before execution; realistic shorter requests can improve queue priority. The estimate below is quota/runtime reservation, not video length. LoRA Hub files are prepared on CPU before GPU reservation.",
elem_classes=["ltx-subtle"],
)
zerogpu_duration_estimate = gr.Markdown(value=_zerogpu_duration_panel(
None, None, None, min(STANDARD_MAX_SECONDS, max(1.0, EFFECTIVE_DEFAULT_DURATION_SECONDS)), False,
EFFECTIVE_DEFAULT_RESOLUTION, EFFECTIVE_DEFAULT_SELECTED_LORAS,
EFFECTIVE_DEFAULT_USE_DIFFUSION_DECODER, EFFECTIVE_DEFAULT_USE_AUTO_DURATION,
))
if IS_FULL_SFT_PROFILE:
gr.Markdown(
"Full/SFT validation profile: **90s validated 25f floor**; >25f uses the evidence-based estimator, and each selected user LoRA adds **8s** reservation margin.",
elem_classes=["ltx-subtle"],
)
if PROMPT_ENHANCER_MODEL is not None:
gr.Markdown(
f"Prompt Tools use a separate **{PROMPT_TOOL_ZEROGPU_DURATION_SECONDS}s GPU reservation** per action.",
elem_classes=["ltx-subtle"],
)
lora_ui = ui_lora.build_lora_ui(
lora_dropdown_factory=_lora_dropdown,
default_strength=EFFECTIVE_DEFAULT_LORA_STRENGTH,
hub_backend=hub_search_backend,
civitai_backend=civitai_backend,
)
# Keep the generation/settings names local and concrete. Discovery-only
# component details stay owned by ltx.ui_lora.
lora_dropdown = lora_ui.dropdown
lora_strength = lora_ui.strength
lora_prepare_status = lora_ui.prepare_status
civitai_api_key = lora_ui.civitai_api_key
with gr.Accordion("Advanced settings", open=False):
seed, randomize_seed = _build_seed_controls(
seed_value=EFFECTIVE_DEFAULT_SEED,
randomize_value=EFFECTIVE_DEFAULT_RANDOMIZE_SEED,
)
use_diffusion_decoder = gr.Checkbox(
value=EFFECTIVE_DEFAULT_USE_DIFFUSION_DECODER,
interactive=bool(DIFFUSION_DECODE_PIPE is not None),
label="Diffusion decoder",
info=(
"Optional iterative decode. Startup RAM-ready / GPU-lazy, NATTEN + tiled decode. "
"Live-passed at 512×512 for 25f and 361f/15s on ZeroGPU large 48GB; Conv VAE remains the default."
),
)
with gr.Accordion("Settings Export / Import", open=False):
gr.Markdown(
"Export writes all portable UI settings plus read-only runtime provenance. "
"Input media and secrets are never embedded. Import applies only the categories you select."
)
export_settings_btn = gr.Button("Export all settings", variant="secondary")
settings_download = gr.DownloadButton("Download settings JSON", value=None, size="sm")
settings_file = gr.File(
label="Import settings JSON",
file_types=[".json"],
file_count="single",
type="filepath",
)
with gr.Row():
import_prompt = gr.Checkbox(True, label="Prompt")
import_generation = gr.Checkbox(True, label="Generation")
import_seed = gr.Checkbox(True, label="Seed")
with gr.Row():
import_lora = gr.Checkbox(True, label="LoRA selection / strength")
import_session_loras = gr.Checkbox(False, label="Session LoRA definitions")
import_settings_btn = gr.Button("Apply selected settings", variant="secondary")
settings_status = gr.Markdown()
go = gr.Button("Generate video", variant="primary", elem_id="generate-btn")
generation_preflight_status = gr.Markdown(
"Resolution/LoRA CPU preflight runs before any ZeroGPU reservation is requested." if IS_ZEROGPU
else "Resolution/LoRA CPU preflight runs before generation starts.", elem_classes=["ltx-subtle"],
)
with gr.Column(scale=7):
out, used_seed, probe_files = _build_result_panel(
result_label="Result",
probe_note="Probe ZIPs contain run info, diagnostics, request log and SHA256 manifest; video remains separate for visual review.",
)
with gr.Accordion("Recent history", open=False):
history_summary = gr.Markdown("No completed runs in this browser session yet.")
history_choice = gr.Dropdown(choices=[], value=None, label="Recent run", interactive=False)
history_restore_btn = gr.Button("Restore settings from selected run", variant="secondary")
if EXAMPLE_ROWS:
gr.Examples(
examples=[[row[0], None, row[1], row[2]] for row in EXAMPLE_ROWS],
inputs=[image, middle_image, end_image, prompt],
label="Examples · click to fill inputs",
cache_examples=False,
)
gr.Markdown(example_runtime.attribution_markdown(EXAMPLE_STATE), elem_classes=["ltx-subtle"])
with gr.Tab("Audio-to-Video"):
gr.Markdown(
"### Audio-to-Video\n"
"The uploaded audio drives video generation while its latent stays frozen in both diffusion stages. "
"The original decoded input waveform remains the final audio track. Current validated profile: **512×512 / 121f / 24fps**. "
"This is audio-reactive generation; frame-exact lip sync is not claimed."
)
if not IS_FULL_SFT_PROFILE:
gr.Markdown(
"**Unavailable outside `full_sft_nf4`.** Switch `MODEL_RUNTIME_PROFILE` in `space_config.py` and restart."
)
else:
required_audio_seconds = float(A2V_FRAMES) / FRAME_RATE
gr.Markdown(
f"Upload at least **{required_audio_seconds:.3f}s** of audio. CPU preflight freezes the source, decodes it with PyAV and "
f"builds the LTX-compatible log-mel cache before the **{int(A2V_ZEROGPU_DURATION_SECONDS)}s** GPU reservation starts."
)
with gr.Row(equal_height=False):
with gr.Column(scale=6):
a2v_image = gr.Image(
label="Start image",
type="filepath",
sources=["upload", "clipboard"],
height=250,
)
a2v_audio = gr.Audio(
label="Driving audio · upload ≥5.042s",
type="filepath",
sources=["upload"],
)
a2v_prompt = gr.Textbox(
label="Prompt",
lines=5,
value="A pair of tabby cats on a bright pink sofa react naturally to the rhythm and dynamics of the supplied audio; coherent motion, stable framing, detailed fur and expressive movement.",
)
a2v_seed, a2v_randomize_seed = _build_seed_controls(
seed_value=42,
randomize_value=False,
)
a2v_go = gr.Button(
"Generate audio-driven video",
variant="primary",
interactive=bool(
EFFECTIVE_A2V_ENABLED
and IS_FULL_SFT_PROFILE
and PIPE_I2V is not None
and UPSAMPLE_PIPE is not None
),
)
a2v_status = gr.Markdown(
"CPU preflight runs first; invalid/short audio fails before GPU quota is requested."
)
with gr.Column(scale=7):
a2v_out, a2v_used_seed, a2v_probe_files = _build_result_panel(
result_label="Audio-to-Video result",
)
if A2V_EXAMPLE_ROWS:
gr.Examples(
examples=A2V_EXAMPLE_ROWS,
inputs=[a2v_image, a2v_audio, a2v_prompt],
label="Example · image + audio + prompt",
cache_examples=False,
)
gr.Markdown(
"Example media is fetched at startup from the pinned [alexnasa/ltx-2-TURBO](https://huggingface.co/spaces/alexnasa/ltx-2-TURBO) donor revision. "
"Only the example media/prompt are reused; generation stays on this Space's LTX-2.5 Full/SFT runtime."
)
ic_ui, pixel_upscaler_ui, inoutpaint_ui = ui_ic_tabs.build_ic_product_tabs(
pipe_ic_ready=PIPE_IC is not None,
colorizer_examples=IC_EXAMPLE_ROWS,
colorizer_attribution=_ic_example_attribution_markdown(),
pixel_upscaler_examples=PIXEL_UPSCALER_EXAMPLE_ROWS,
pixel_upscaler_attribution=_pixel_upscaler_example_attribution_markdown(),
inoutpaint_examples=INOUTPAINT_EXAMPLE_ROWS,
inoutpaint_attribution=_inoutpaint_example_attribution_markdown(),
)
# Keep the established app/event names below stable while presentation
# ownership lives in ltx/ui_ic_tabs.py.
ic_video = ic_ui.video
ic_prompt = ic_ui.prompt
ic_profile = ic_ui.profile
ic_seed = ic_ui.seed
ic_randomize_seed = ic_ui.randomize_seed
ic_go = ic_ui.go
ic_status = ic_ui.status
ic_out = ic_ui.output
ic_used_seed = ic_ui.used_seed
ic_probe_files = ic_ui.probe_files
pixel_upscaler_video = pixel_upscaler_ui.video
pixel_upscaler_prompt = pixel_upscaler_ui.prompt
pixel_upscaler_seed = pixel_upscaler_ui.seed
pixel_upscaler_randomize_seed = pixel_upscaler_ui.randomize_seed
pixel_upscaler_go = pixel_upscaler_ui.go
pixel_upscaler_status = pixel_upscaler_ui.status
pixel_upscaler_out = pixel_upscaler_ui.output
pixel_upscaler_used_seed = pixel_upscaler_ui.used_seed
pixel_upscaler_probe_files = pixel_upscaler_ui.probe_files
inoutpaint_mode = inoutpaint_ui.mode
inoutpaint_video = inoutpaint_ui.video
inoutpaint_mask = inoutpaint_ui.mask
inoutpaint_layout = inoutpaint_ui.layout
inoutpaint_dilation = inoutpaint_ui.dilation
inoutpaint_prompt = inoutpaint_ui.prompt
inoutpaint_seed = inoutpaint_ui.seed
inoutpaint_randomize_seed = inoutpaint_ui.randomize_seed
inoutpaint_go = inoutpaint_ui.go
inoutpaint_status = inoutpaint_ui.status
inoutpaint_out = inoutpaint_ui.output
inoutpaint_used_seed = inoutpaint_ui.used_seed
inoutpaint_probe_files = inoutpaint_ui.probe_files
if SPACE_DEBUG:
with gr.Tab("Developer / Probes"):
gr.Markdown(
"### Developer / Probes\n"
"Maintainer and Research Probe controls are intentionally separated from ordinary product tabs."
)
with gr.Accordion("Maintainer Probe", open=False):
maintainer_gate_status = gr.Markdown(_maintainer_gate_markdown())
_maintainer_initial_profile = MAINTAINER_PROBE_CURRENT_GATES[0] if MAINTAINER_PROBE_CURRENT_GATES else None
maintainer_probe_profile = gr.Dropdown(
choices=MAINTAINER_PROBE_CHOICES,
value=_maintainer_initial_profile,
label="Probe profile · optional unless listed as current gate",
interactive=True,
)
maintainer_probe_description = gr.Markdown(
_maintainer_probe_profile_description(_maintainer_initial_profile)
)
maintainer_probe_run = gr.Button(
"Run Probe",
variant="primary",
interactive=bool(
_maintainer_initial_profile
and IS_FULL_SFT_PROFILE
and PIPE_I2V is not None
and UPSAMPLE_PIPE is not None
and (_maintainer_initial_profile != MAINTAINER_PROBE_FULL_SFT_30S_STAGE2_DIFFUSION or DIFFUSION_DECODE_PIPE is not None)
),
)
maintainer_probe_status = gr.Markdown(
"No Maintainer Probe has run in this browser session."
)
maintainer_probe_files = gr.File(
label="Maintainer Probe artifacts · one ZIP per request",
file_count="multiple",
interactive=False,
)
gr.Markdown(
f"Runtime: **{RUNTIME_PROFILE}** · ZeroGPU size: **{EFFECTIVE_ZEROGPU_GPU_SIZE}** · Candidate: `{CANDIDATE_ID}`. "
"Probe profiles are retained only when their purpose and safety contract remain explicit; profile presence does not imply a promotion requirement.",
elem_classes=["ltx-subtle"],
)
with gr.Accordion("Research Probe · free research", open=False):
gr.Markdown(
"**Gate-free research line.** Profiles here may be run at any time and may fail without affecting LIVE/candidate promotion. "
"Default policy is maximum information gain and adventurous exploration; shared mutable runtime is still protected by serialization until a profile is proven isolated."
)
research_probe_profile = gr.Dropdown(
choices=RESEARCH_PROBE_CHOICES,
value=None,
label="Research profile · never a promotion gate",
interactive=True,
)
research_probe_description = gr.Markdown(_research_probe_profile_description(None))
research_probe_run = gr.Button(
"Run Research Probe",
variant="secondary",
interactive=False,
)
research_probe_status = gr.Markdown("No Research Probe has run in this browser session.")
research_probe_files = gr.File(
label="Research Probe artifacts · one ZIP per request",
file_count="multiple",
interactive=False,
)
gr.Markdown(
"Research profiles are intentionally allowed to be aggressive, heavy, risky, or unsuccessful when the expected information value justifies it. "
"This initial set uses the shared Full/SFT runtime and therefore remains serial with product/Maintainer GPU work.",
elem_classes=["ltx-subtle"],
)
# User-only duration control events avoid function-update `.change` fan-out.
experimental_long_event = experimental_long.input(
_duration_slider_update, [experimental_long, duration_seconds, resolution], duration_seconds,
queue=False, show_progress="hidden",
api_visibility=INTERNAL_API_VISIBILITY,
)
resolution_event = resolution.input(
_resolution_duration_controls, [resolution, experimental_long, duration_seconds],
[experimental_long, duration_seconds], queue=False, show_progress="hidden",
api_visibility=INTERNAL_API_VISIBILITY,
)
custom_resolution_duration_event = _bind_custom_resolution_editor(
resolution_component=resolution, width_input=custom_resolution_width, height_input=custom_resolution_height,
apply_button=apply_custom_resolution_btn, status_output=custom_resolution_status, experimental_long=experimental_long,
duration_seconds=duration_seconds, api_visibility=INTERNAL_API_VISIBILITY)
gr.on(
triggers=[image.change, middle_image.change, end_image.change],
fn=_conditioning_mode_status_markdown,
inputs=[image, middle_image, end_image],
outputs=conditioning_mode_status,
queue=False,
show_progress="hidden",
api_visibility=INTERNAL_API_VISIBILITY,
)
if IS_ZEROGPU:
quota_inputs = [image, middle_image, end_image, duration_seconds, experimental_long, resolution, lora_dropdown, use_diffusion_decoder, use_auto_duration]
preview_kwargs = dict(
fn=_zerogpu_duration_panel, inputs=quota_inputs, outputs=zerogpu_duration_estimate,
queue=False, show_progress="hidden", api_visibility=INTERNAL_API_VISIBILITY,
)
duration_seconds.release(**preview_kwargs)
gr.on(
triggers=[image.change, middle_image.change, end_image.change, lora_dropdown.change, use_diffusion_decoder.input, use_auto_duration.input],
**preview_kwargs,
)
experimental_long_event.then(**preview_kwargs)
resolution_event.then(**preview_kwargs)
custom_resolution_duration_event.then(**preview_kwargs)
if SPACE_DEBUG:
maintainer_probe_profile.change(
_maintainer_probe_profile_ui,
inputs=[maintainer_probe_profile],
outputs=[maintainer_probe_description, maintainer_probe_run],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
maintainer_probe_event = maintainer_probe_run.click(
run_maintainer_probe,
inputs=[maintainer_probe_profile, session_id_state],
outputs=[maintainer_probe_status, maintainer_latest_probe_state],
api_name="run_maintainer_probe",
trigger_mode="multiple",
show_progress="full", show_progress_on=maintainer_probe_status,
concurrency_limit=1, concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
maintainer_probe_event.success(
_append_probe_output,
inputs=[maintainer_probe_files_state, maintainer_latest_probe_state],
outputs=[maintainer_probe_files_state, maintainer_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
maintainer_probe_event.failure(
_refresh_latest_probe_output,
inputs=[maintainer_probe_files_state, session_id_state],
outputs=[maintainer_probe_files_state, maintainer_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
research_probe_profile.change(
_research_probe_profile_ui,
inputs=[research_probe_profile],
outputs=[research_probe_description, research_probe_run],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
research_probe_event = research_probe_run.click(
run_research_probe,
inputs=[research_probe_profile, session_id_state],
outputs=[research_probe_status, research_latest_probe_state],
api_name="run_research_probe",
trigger_mode="multiple",
show_progress="full", show_progress_on=research_probe_status,
concurrency_limit=1, concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
research_probe_event.success(
_append_probe_output,
inputs=[research_probe_files_state, research_latest_probe_state],
outputs=[research_probe_files_state, research_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
research_probe_event.failure(
_refresh_latest_probe_output,
inputs=[research_probe_files_state, session_id_state],
outputs=[research_probe_files_state, research_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
enhance_prompt_btn.click(
enhance_prompt_separate,
inputs=[prompt, image, middle_image, end_image, session_id_state],
outputs=[prompt, prompt_tools_status],
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
translate_prompt_btn.click(
translate_prompt_separate,
inputs=[prompt, translate_manual_enabled, translate_manual_prompt, session_id_state],
outputs=[prompt, prompt_tools_status],
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
write_prompt_btn.click(
write_prompt_from_seed_separate,
inputs=[prompt, write_manual_enabled, write_manual_prompt, session_id_state],
outputs=[prompt, prompt_tools_status],
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
ui_lora.wire_lora_events(
lora_ui,
prompt=prompt,
custom_lora_state=custom_lora_state,
prepared_lora_state=prepared_lora_state,
handlers=ui_lora.LoraHandlers(
apply_hub_quick_selection=apply_hub_lora_search_selection,
inspect_hub_repo=inspect_hub_lora_repo,
search_hf_models=search_hf_lora_models,
apply_hf_full_selection=apply_hf_full_search_selection,
search_civitai_models=search_civitai_models,
load_more_civitai_models=load_more_civitai_models,
inspect_civitai_gallery_selection=inspect_civitai_gallery_selection,
resolve_civitai_url=resolve_civitai_url,
inspect_civitai_version_selection=inspect_civitai_version_selection,
apply_civitai_trigger_words=apply_civitai_trigger_words,
load_civitai_example_prompts=load_civitai_example_prompts,
apply_civitai_example_prompt=apply_civitai_example_prompt,
add_civitai_session_lora=add_civitai_session_lora,
add_hf_session_lora=add_session_lora,
remove_selected_session_loras=remove_selected_session_loras,
prepare_selected_loras=prepare_selected_loras,
invalidate_prepared_loras=_invalidate_prepared_loras,
),
)
export_settings_btn.click(
_write_settings_export,
inputs=[
prompt, duration_seconds, experimental_long, resolution, seed, randomize_seed,
lora_dropdown, lora_strength, custom_lora_state, use_diffusion_decoder, use_auto_duration, image, middle_image, end_image, session_id_state,
],
outputs=[settings_download, settings_status],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
import_settings_event = import_settings_btn.click(
_import_settings,
inputs=[
settings_file, import_prompt, import_generation, import_seed, import_lora, import_session_loras,
prompt, duration_seconds, experimental_long, resolution, seed, randomize_seed,
lora_dropdown, lora_strength, custom_lora_state, use_diffusion_decoder, use_auto_duration,
],
outputs=[
prompt, duration_seconds, experimental_long, resolution, seed, randomize_seed,
lora_dropdown, lora_strength, custom_lora_state, use_diffusion_decoder, use_auto_duration, settings_status,
],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
history_restore_event = history_restore_btn.click(
_restore_history_settings,
inputs=[
history_state, history_choice, prompt, duration_seconds, experimental_long, resolution,
seed, randomize_seed, lora_dropdown, lora_strength, custom_lora_state, use_diffusion_decoder, use_auto_duration,
],
outputs=[
prompt, duration_seconds, experimental_long, resolution, seed, randomize_seed,
lora_dropdown, lora_strength, custom_lora_state, use_diffusion_decoder, use_auto_duration, settings_status,
],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
_sync_resolution_editor_after(
(import_settings_event, history_restore_event), resolution_component=resolution,
width_input=custom_resolution_width, height_input=custom_resolution_height, status_output=custom_resolution_status,
api_visibility=INTERNAL_API_VISIBILITY)
if IS_ZEROGPU:
# Programmatic restore paths normalize duration controls, then refresh quota exactly once.
for _settings_event in (import_settings_event, history_restore_event):
_settings_event.then(
_resolution_duration_controls, [resolution, experimental_long, duration_seconds],
[experimental_long, duration_seconds], queue=False, show_progress="hidden",
api_visibility=INTERNAL_API_VISIBILITY,
).then(**preview_kwargs)
a2v_prepare_event = a2v_go.click(
prepare_audio_to_video,
inputs=[a2v_audio, a2v_image, a2v_prompt, a2v_seed, a2v_randomize_seed, session_id_state],
outputs=[a2v_prepared_state, a2v_status, a2v_seed],
api_name="prepare_audio_to_video",
api_visibility=INTERNAL_API_VISIBILITY,
)
a2v_generate_event = a2v_prepare_event.success(
generate_audio_to_video,
inputs=[a2v_prepared_state, session_id_state],
outputs=[a2v_out, a2v_used_seed, a2v_status, a2v_latest_probe_state],
api_name="generate_audio_to_video",
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
a2v_generate_event.success(
_append_probe_output,
inputs=[a2v_probe_files_state, a2v_latest_probe_state],
outputs=[a2v_probe_files_state, a2v_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
a2v_generate_event.failure(
_refresh_latest_probe_output,
inputs=[a2v_probe_files_state, session_id_state],
outputs=[a2v_probe_files_state, a2v_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
ic_prepare_event = ic_go.click(
prepare_ic_colorizer,
inputs=[ic_video, ic_prompt, ic_profile, ic_seed, ic_randomize_seed, session_id_state],
outputs=[ic_prepared_state, ic_status, ic_seed],
api_name="prepare_ic_colorizer_probe",
api_visibility=INTERNAL_API_VISIBILITY,
)
ic_generate_event = ic_prepare_event.success(
generate_ic_colorizer,
inputs=[ic_prepared_state, session_id_state],
outputs=[ic_out, ic_used_seed, ic_status, ic_latest_probe_state],
api_name="generate_ic_colorizer_probe",
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
ic_generate_event.success(
_append_probe_output,
inputs=[ic_probe_files_state, ic_latest_probe_state],
outputs=[ic_probe_files_state, ic_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
ic_generate_event.failure(
_refresh_latest_probe_output,
inputs=[ic_probe_files_state, session_id_state],
outputs=[ic_probe_files_state, ic_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
pixel_upscaler_prepare_event = pixel_upscaler_go.click(
prepare_pixel_upscaler,
inputs=[
pixel_upscaler_video, pixel_upscaler_prompt, pixel_upscaler_seed,
pixel_upscaler_randomize_seed, session_id_state,
],
outputs=[pixel_upscaler_prepared_state, pixel_upscaler_status, pixel_upscaler_seed],
api_name="prepare_pixel_spatial_upscaler",
api_visibility=INTERNAL_API_VISIBILITY,
)
pixel_upscaler_generate_event = pixel_upscaler_prepare_event.success(
generate_pixel_upscaler,
inputs=[pixel_upscaler_prepared_state, session_id_state],
outputs=[
pixel_upscaler_out, pixel_upscaler_used_seed, pixel_upscaler_status,
pixel_upscaler_latest_probe_state,
],
api_name="generate_pixel_spatial_upscaler",
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
pixel_upscaler_generate_event.success(
_append_probe_output,
inputs=[pixel_upscaler_probe_files_state, pixel_upscaler_latest_probe_state],
outputs=[pixel_upscaler_probe_files_state, pixel_upscaler_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
pixel_upscaler_generate_event.failure(
_refresh_latest_probe_output,
inputs=[pixel_upscaler_probe_files_state, session_id_state],
outputs=[pixel_upscaler_probe_files_state, pixel_upscaler_probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
inoutpaint_prepare_event = inoutpaint_go.click(
prepare_inoutpaint,
inputs=[
inoutpaint_video, inoutpaint_mask, inoutpaint_prompt, inoutpaint_mode,
inoutpaint_layout, inoutpaint_dilation, inoutpaint_seed, inoutpaint_randomize_seed,
session_id_state,
],
outputs=[inoutpaint_prepared_state, inoutpaint_status, inoutpaint_seed],
api_name="prepare_inoutpaint", api_visibility=INTERNAL_API_VISIBILITY,
)
inoutpaint_generate_event = inoutpaint_prepare_event.success(
generate_inoutpaint,
inputs=[inoutpaint_prepared_state, session_id_state],
outputs=[inoutpaint_out, inoutpaint_used_seed, inoutpaint_status, inoutpaint_latest_probe_state],
api_name="generate_inoutpaint", concurrency_limit=1, concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
inoutpaint_generate_event.success(
_append_probe_output,
inputs=[inoutpaint_probe_files_state, inoutpaint_latest_probe_state],
outputs=[inoutpaint_probe_files_state, inoutpaint_probe_files],
queue=False, api_visibility=INTERNAL_API_VISIBILITY,
)
inoutpaint_generate_event.failure(
_refresh_latest_probe_output,
inputs=[inoutpaint_probe_files_state, session_id_state],
outputs=[inoutpaint_probe_files_state, inoutpaint_probe_files],
queue=False, api_visibility=INTERNAL_API_VISIBILITY,
)
clear_generation_event = go.click(
_clear_generation_result,
inputs=[],
outputs=[out, used_seed],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
resolution_preflight_event = clear_generation_event.then(
_resolution_input_preflight,
inputs=[resolution],
outputs=[generation_preflight_status],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
lora_prepare_before_generate = resolution_preflight_event.success(
prepare_selected_loras,
inputs=[lora_dropdown, custom_lora_state, civitai_api_key],
outputs=[prepared_lora_state, lora_prepare_status],
api_visibility=INTERNAL_API_VISIBILITY,
)
generation_ready_event = lora_prepare_before_generate
if IS_ZEROGPU:
generation_ready_event = lora_prepare_before_generate.success(
_generation_duration_preflight,
inputs=[image, middle_image, end_image, duration_seconds, resolution, lora_dropdown, use_diffusion_decoder, use_auto_duration],
outputs=[generation_preflight_status],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
generation_event = generation_ready_event.success(
generate,
inputs=[
prompt,
image,
middle_image,
end_image,
duration_seconds,
experimental_long,
resolution,
seed,
randomize_seed,
lora_dropdown,
lora_strength,
custom_lora_state,
prepared_lora_state,
use_diffusion_decoder,
use_auto_duration,
session_id_state,
history_state,
],
outputs=[
out, seed, used_seed, latest_probe_state,
history_state, history_choice, history_summary,
],
concurrency_limit=1,
concurrency_id=GPU_CONCURRENCY_ID,
api_visibility=INTERNAL_API_VISIBILITY,
)
generation_event.success(
_append_probe_output,
inputs=[probe_files_state, latest_probe_state],
outputs=[probe_files_state, probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
generation_event.failure(
_refresh_latest_probe_output,
inputs=[probe_files_state, session_id_state],
outputs=[probe_files_state, probe_files],
queue=False,
api_visibility=INTERNAL_API_VISIBILITY,
)
demo.queue(default_concurrency_limit=1).launch(css=CSS, ssr_mode=False)
|