File size: 113,695 Bytes
fb7c72e 9add88b fb7c72e 9add88b cf6ac90 7b932b1 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b 0826f53 9add88b b8e37f1 0826f53 9add88b cf6ac90 9add88b cf6ac90 9add88b 7dc4c93 cdaf17f 9add88b cdaf17f 9add88b f0ae2cb 9add88b cf6ac90 9add88b cf6ac90 9add88b cdaf17f 9add88b cf6ac90 9add88b 5eb7b84 7a24149 9add88b cf05127 9add88b cf6ac90 e166347 cc80c12 9add88b 93fe395 cf05127 9add88b cdaf17f 9add88b cdaf17f 9add88b 9a96d60 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 6fd0800 16af102 6fd0800 16af102 6fd0800 cf6ac90 6fd0800 cf6ac90 16af102 cf6ac90 6fd0800 cf6ac90 16af102 cf6ac90 6fd0800 cf6ac90 16af102 cf6ac90 6fd0800 cf6ac90 6fd0800 cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b 6fd0800 9add88b 6fd0800 9add88b 0826f53 9add88b 0826f53 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 6fd0800 cf6ac90 16af102 cf6ac90 9add88b cf6ac90 9add88b cf6ac90 9add88b cf6ac90 6fd0800 cf6ac90 16af102 cf6ac90 9add88b cf6ac90 9add88b |
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 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 |
import gradio as gr
import torch
#import numpy as np
import modin.pandas as pd
from PIL import Image
from diffusers import DiffusionPipeline
import os
##########
#
# Original script by:
# https://huggingface.co/Manjushri
#
# This version have been adapted from that person's versions.
#
##########
# Tested with gradio version 4.8.0
# https://www.gradio.app/main/docs/interface
##########
# To launch this script, use the following in the command prompt, taking off
# the # at the start. (You will need to adjust the start of the path if you
# have changed the location)
#cd C:\Diffusers && .venv\Scripts\activate.bat && py .venv\sdxl_and_photoreal\sdxl_and_photoreal.py
##########
# IMPORTANT NOTES:
#
# You must have a NVIDIA graphics card in your computer with Cuda
# installed to use this script. It will not work on just a CPU on
# Windows.
#
# If not using "enable_model_cpu_offload" or
# "enable_sequential_cpu_offload", memory usage will remain high until
# command prompt is closed. (whether image is being created or not)
###############################################################################
###############################################################################
#
#
#
# Begin Configurations
#
#
#
###############################################################################
###############################################################################
#
# Main Directory
#
# This is where everything goes. Your Python virtual environment should
# be here. Model data will be stored here. (unless you change the next
# configuration) If configured, imagery will also be automatically be
# saved here.
#
main_dir = "C:/Diffusers"
####################
#
# Use Custom Hugging Face Cache Directory
#
# The folder where model data is stored can get huge. I choose to add it
# to a place where I am more likely to notice it more often. If you use
# other Hugging Face things however, and will use these models in those
# other things, then you might want to consider not having this here as
# it would duplicate the model data.
#
# If set to 1, the data would be here:
# C:\Diffusers\model_data
#
# If set to 0, the data would be here:
# %USERPROFILE%/.cache/huggingface/hub
# Which would look like this, where {Username} is the username of
# your Windows account:
# C:\Users\{Username}\.cache\huggingface\hub
#
# You need to clean out the folder occasionally as this folder will get
# extremely large. Eventually, it would take up all the space on your
# computer.
#
use_custom_hugging_face_cache_dir = 1
#####
#
# Name of Model Data Folder
#
# This is where all the model data will go. (unless you changed it in the
# previous configuration) This folder will get very large. You need to
# clean it out manually occasionally.
#
cache_directory_folder_name = "model_data"
####################
#
# Default Base Model
#
# This will automatically be SDXL Turbo if you are running this on a CPU.
#
default_base_model = "sdxl"
####################
#
# Auto Save Imagery
#
# You can automatically save the image file, and a text file with the
# prompt details.
#
auto_save_imagery = 1
#####
#
# Name of Saved Images Folder
#
# You can change the name of this folder if you want. Imagery will be
# saved in a folder called "saved_images" in the directory configured
# in "main_dir". (the saved images folder will be created
# automatically) A directory for each day will be created in this
# folder. Imagery will then be placed in each folder.
#
saved_images_folder_name = "saved_images"
####################
#
# Auto Open Browser From Command Prompt
#
auto_open_browser = 1
####################
#
# Make Seed Selection A Textbox
#
# If you use a slider or number field for the seed, some seeds can't be
# duplicated using those fields. If you enter a number greater than
# 9007199254740992, the seed won't reliably be used. Check the text
# details to see if it was used. This is a technical limitation as of
# writing this. See the bug report here:
# https://github.com/gradio-app/gradio/issues/5354
#
# Using the slider, and not entering a number, might be the way to get
# reliable numbers above that number. Just don't then use the up and down
# arrows in the field to go up or down a number.
#
# The way to use seeds higher than that reliably is to set this variable
# to 1.
make_seed_selection_a_textbox = 0
####################
#
# Include Close Command Prompt / Cancel Button
#
# This doesn't work well at all. It just closes the command prompt. And
# it currently isn't canceling image creation either when used. Don't use
# it.
#
enable_close_command_prompt_button = 0
####################
#
# Use Denoising Start In Base Model When Using Refiner
#
# If set to "1", refining will end at the percent (expressed as decimal)
# defined in the denoising start for the refiner. If the steps set are
# 100, and the denoising start value is 0.75, the base model will run for
# 75 steps. The refiner will then run for 25 steps.
#
default_use_denoising_start_in_base_model_when_using_refiner = 0
####################
#
# Base Model Output To Refiner Is In Latent Space
#
# If set to "1", base model output is in latent space instead of PIL
# image when sent to refiner.
#
default_base_model_output_to_refiner_is_in_latent_space = 1
####################
#
# Log Generation Times
#
# Log generation times to saved text output. The initial time it takes to
# load a model is not included in the generation time.
#
log_generation_times = 1
####################
#
# Use Image Gallery
#
# There is a bug in downloading images:
# https://github.com/gradio-app/gradio/issues/6486
# It saves as HTML rather than image.
#
# If you use the gallery, you can turn the download button off for now.
# They can still right click and save the image.
#
use_image_gallery = 0
show_download_button_for_gallery = 0
####################
#
# Show Image Creation Progress Log
#
# This adds the current step that image generation is on.
#
show_image_creation_progress_log = 1
####################
#
# Show Messages In Command Prompt
#
# Messages will be printed in command prompt.
#
show_messages_in_command_prompt = 1
####################
#
# Show Messages In Modal On Page
#
# A popup appears in the top right corner on the page.
#
show_messages_in_modal_on_page = 0
####################
#
# Up Next Is Various Configuration Arrays and Objects
#
####################
base_model_array = [
"sdxl",
"photoreal",
"sdxl_turbo",
"sd_1_5_runwayml"
]
base_model_names_object = {
"sdxl": "Stable Diffusion XL 1.0",
"photoreal": "PhotoReal",
"sdxl_turbo": "Stable Diffusion XL Turbo",
"sd_1_5_runwayml": "Stable Diffusion 1.5"
}
####################
#
# "sdxl_default"
#
# - My customized configurations. (subject to change)
#
# "sdxl_2023-11-12"
#
# - Valid from November 12th to present.
# Number of steps in upscaler changed from 5 to 15.
#
# "sdxl_2023-09-05"
#
# - Valid from September 5th to November 12th.
# There were changes on this date.
#
# "photoreal_default"
#
# - My customized configurations. (subject to change)
# "circulus/canvers-real-v3.7.5"
#
# Seeds do not match the online PhotoReal version.
#
# "photoreal_2023-11-12"
#
# - Valid from November 12th to present.
# New base model: "circulus/canvers-real-v3.7.5"
#
# "photoreal_2023-09-01"
#
# - Valid from September 1st to November 12th.
# "circulus/canvers-realistic-v3.6" was already in effect.
# But there were changes on this date.
#
# "sdxl_turbo_default"
#
# - My customized configurations. (subject to change)
#
# "sd_1_5_runwayml_default"
#
# - My customized configurations. (subject to change)
#
base_model_object_of_model_configuration_arrays = {
"sdxl": [
"sdxl_default",
"sdxl_2023-11-12",
"sdxl_2023-09-05"
],
"photoreal": [
"photoreal_default",
"photoreal_2023-11-12",
"photoreal_2023-09-01"
],
"sdxl_turbo": [
"sdxl_turbo_default"
],
"sd_1_5_runwayml": [
"sd_1_5_runwayml_default"
]
}
####################
model_configuration_names_object = {
"sdxl_default": "1.0 - Default (subject to change)",
"sdxl_2023-11-12": "1.0 (2023-11-12 online config)",
"sdxl_2023-09-05": "1.0 (2023-09-05 online config)",
"photoreal_default": "3.7.5 - Default (subject to change)",
"photoreal_2023-11-12": "3.7.5 (2023-11-12 online config)",
"photoreal_2023-09-01": "3.6 (2023-09-01 online config)",
"sdxl_turbo_default": "Default (subject to change)",
"sd_1_5_runwayml_default": "1.5 - Default (subject to change)"
}
model_configuration_links_object = {
"sdxl_default": "stabilityai/stable-diffusion-xl-base-1.0",
"sdxl_2023-11-12": "stabilityai/stable-diffusion-xl-base-1.0",
"sdxl_2023-09-05": "stabilityai/stable-diffusion-xl-base-1.0",
"photoreal_default": "circulus/canvers-real-v3.7.5",
"photoreal_2023-11-12": "circulus/canvers-real-v3.7.5",
"photoreal_2023-09-01": "circulus/canvers-realistic-v3.6",
"sdxl_turbo_default": "stabilityai/sdxl-turbo",
"sd_1_5_runwayml_default": "runwayml/stable-diffusion-v1-5"
}
model_configuration_force_refiner_object = {
"sdxl_2023-11-12": 1,
"sdxl_2023-09-05": 1
}
# For now, the ones that force the refiner also have the "Refiner Number of
# Iterations" available.
model_configuration_include_refiner_number_of_steps_object = model_configuration_force_refiner_object
#model_configuration_include_refiner_number_of_steps_object = {
# "sdxl_2023-11-12": 1,
# "sdxl_2023-09-05": 1
#}
####################
hugging_face_refiner_partial_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
hugging_face_upscaler_partial_path = "stabilityai/sd-x2-latent-upscaler"
####################
base_model_model_configuration_defaults_object = {
"sdxl": "sdxl_default",
"photoreal": "photoreal_default",
"sdxl_turbo": "sdxl_turbo_default",
"sd_1_5_runwayml": "sd_1_5_runwayml_default"
}
####################
#
# Links:
#
# SD-XL 1.0-base Model Card
# https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0
#
# SD-XL 1.0-refiner Model Card
# https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0
#
# Stable Diffusion x2 latent upscaler model card
# https://huggingface.co/stabilityai/sd-x2-latent-upscaler
#
# PhotoReal
# 3.7.5: https://huggingface.co/circulus/canvers-real-v3.7.5
# 3.6: https://huggingface.co/circulus/canvers-realistic-v3.6
#
# SDXL Turbo
# https://huggingface.co/stabilityai/sdxl-turbo
#
# Stable Diffusion v1-5 (runwayml)
# https://huggingface.co/runwayml/stable-diffusion-v1-5
#
####################
#
# Determine automatically if on CPU or GPU
#
# CPU will not work on Windows.
#
device = "cpu"
if torch.cuda.is_available():
device = "cuda"
PYTORCH_CUDA_ALLOC_CONF = {
"max_split_size_mb": 8000
}
torch.cuda.max_memory_allocated(
device = device
)
torch.cuda.empty_cache()
if device == "cpu":
default_base_model = "sdxl_turbo"
####################
default_prompt = ""
default_negative_prompt = ""
default_width = 768
default_height = 768
default_guidance_scale_value = 7
default_base_model_base_model_num_inference_steps = 50
default_base_model_base_model_num_inference_steps_for_sdxl_turbo = 2
#default_seed_maximum = 999999999999999999
default_seed_maximum = 1000000000000000000
default_seed_value = 876678173805928800
# If you turn off the refiner it will not be available in the display unless
# you select an online configuration option that requires it.
enable_refiner = 1
enable_upscaler = 1
# Selected on form as a default?
default_refiner_selected = 0
default_upscaler_selected = 0
# Accordion visible on load?
#
# 0 If selected as default, will be open. Otherwise, closed.
# 1 Always starts open
default_refiner_accordion_open = 1
default_upscaler_accordion_open = 1
# xFormers:
#
# https://huggingface.co/docs/diffusers/optimization/xformers
use_xformers = 1
# Scaled dot product attention (SDPA) is used by default for PyTorch 2.0. To
# use default instead, set this to 1.
#
# https://huggingface.co/docs/diffusers/optimization/torch2.0#scaled-dot-product-attention
use_default_attn_processor = 0
display_xformers_usage_in_prompt_info = 1
include_transformers_version_in_prompt_info = 1
display_default_attn_processor_usage_in_prompt_info = 1
# You can't select both sequential and model cpu offloading. If you select
# both, model cpu offloading will be used.
use_sequential_cpu_offload_for_base_model = 1
use_sequential_cpu_offload_for_refiner = 1
use_sequential_cpu_offload_for_upscaler = 1
use_model_cpu_offload_for_base_model = 0
use_model_cpu_offload_for_refiner = 0
use_model_cpu_offload_for_upscaler = 0
if default_base_model == "photoreal":
# PhotoReal
default_seed_value = 3648905360627576
elif default_base_model == "sdxl_turbo":
# SDXL Turbo
default_seed_value = 2725116121543
#elif default_base_model == "sd_1_5_runwayml":
# SD 1.5
else:
# SDXL
default_width = 1024
default_height = 1024
default_guidance_scale_value = 10
# Must be multiple of 8
width_and_height_input_slider_steps = 8
opening_html = ""
if device == "cpu":
opening_html = "<span style=\"font-weight: bold; color: #c00;\">THIS APP IS EXCEPTIONALLY SLOW!</span><br/>This app is not running on a GPU. The first time it loads after the space is rebuilt it might take 10 minutes to generate a SDXL Turbo image. It may take 2 to 3 minutes after that point to do two steps. For other models, it may take hours to create a single image."
ending_html = """This app allows you to try to match images that can be generated using several tools online. (<a href=\"https://huggingface.co/spaces/Manjushri/SDXL-1.0\" target=\"_blank\">Stable Diffusion XL</a>, <a href=\"https://huggingface.co/spaces/Manjushri/PhotoReal-V3.7.5\" target=\"_blank\">PhotoReal with SDXL 1.0 Refiner</a> and <a href=\"https://huggingface.co/spaces/diffusers/unofficial-SDXL-Turbo-i2i-t2i\" target=\"_blank\">SDXL Turbo Unofficial Demo</a>) You can select the base model you want to use in the first dropdown option. The second configuration option involves choosing which version and/or configuration to choose. Certain configurations try to match the version online, taking into account changes that were made over time. Another configuration involves a default configuration I choose and is subject to change while I am still designing this app.
Tokens are not individual characters. If the prompt length is too long, the display will notify you what part of the prompt wasn't used. Changing just the image dimensions alone will change the image generated. For some models, trying to make a large image, such as 1024x1024, may add extra people and come out worse than using smaller dimensions. If you have a seed greater than 9007199254740992, it may not be processed correctly. Make sure the prompt matches the seed you entered. (shown in the \"Prompt Information\" section once you create an image) If it doesn't, set \"make_seed_selection_a_textbox\" to 1 in the script. This bug is described <a href=\"https://github.com/gradio-app/gradio/issues/5354\" target=\"_blank\">here</a>.
The original script for this app was written by <a href=\"https://huggingface.co/Manjushri\" target=\"_blank\">Manjushri</a>."""
refiner_and_upscaler_status_opening_html = "<div style=\"text-align: center;\">"
refiner_and_upscaler_status_closing_html = "</div>"
refiner_on_text = "Refiner is on. "
refiner_off_text = "Refiner is off. "
upscaler_on_text = "Upscaler is on. "
upscaler_off_text = "Upscaler is off. "
number_of_reserved_tokens = 2
###############################################################################
###############################################################################
#
#
#
# End Configurations
#
#
#
###############################################################################
###############################################################################
try:
if (str(os.uname()).find("magicfixeseverything") >= 0):
script_being_run_on_hugging_face = 1
except:
script_being_run_on_hugging_face = 0
if script_being_run_on_hugging_face == 1:
use_custom_hugging_face_cache_dir = 0
auto_save_imagery = 0
show_messages_in_modal_on_page = 0
show_messages_in_command_prompt = 1
if device == "cpu":
show_image_creation_progress_log = 1
ending_html = """
If you would like to download this app to run offline on a Windows computer that has a NVIDIA graphics card, click <a href=\"https://huggingface.co/spaces/magicfixeseverything/ai_image_creation/resolve/main/ai_image_creation.zip\">here</a> to download it.
""" + ending_html
hugging_face_hub_is_offline = 0
if script_being_run_on_hugging_face == 0:
if (
("HF_HUB_OFFLINE" in os.environ) and
(int(os.environ["HF_HUB_OFFLINE"]) == 1)
):
hugging_face_hub_is_offline = 1
if hugging_face_hub_is_offline == 0:
print ("Note: The Hugging Face cache directory does not automatically delete older data. Over time, it could eventually grow to use all the space on the drive it is on. You either need to manually clean out the folder occasionally or see Instructons.txt on how to not automatically update data once you have downloaded everything you need.")
if device == "cuda":
PYTORCH_CUDA_ALLOC_CONF = {
"max_split_size_mb": 8000
}
torch.cuda.max_memory_allocated(
device = device
)
torch.cuda.empty_cache()
saved_images_dir = main_dir + "/" + saved_images_folder_name
hugging_face_cache_dir = main_dir + "/" + cache_directory_folder_name
if not os.path.exists(hugging_face_cache_dir):
os.makedirs(hugging_face_cache_dir)
if auto_save_imagery == 1:
from datetime import datetime
import time
if log_generation_times == 1:
import time
if device == "cpu":
use_sequential_cpu_offload_for_base_model = 0
use_sequential_cpu_offload_for_refiner = 0
use_sequential_cpu_offload_for_upscaler = 0
use_model_cpu_offload_for_base_model = 0
use_model_cpu_offload_for_refiner = 0
use_model_cpu_offload_for_upscaler = 0
use_xformers = 0
if (
(use_sequential_cpu_offload_for_base_model == 1) and
(use_model_cpu_offload_for_base_model == 1)
):
use_sequential_cpu_offload_for_base_model = 0
if (
(use_sequential_cpu_offload_for_refiner == 1) and
(use_model_cpu_offload_for_refiner == 1)
):
use_sequential_cpu_offload_for_refiner = 0
if (
(use_sequential_cpu_offload_for_upscaler == 1) and
(use_model_cpu_offload_for_upscaler == 1)
):
use_sequential_cpu_offload_for_upscaler = 0
def error_function(
text_message
):
print (text_message)
gr.Error(text_message)
exit(1)
# Don't change this one
default_model_configuration_object = {
"sdxl_default": 1,
"photoreal_default": 1,
"sdxl_turbo_default": 1,
"sd_1_5_runwayml_default": 1
}
additional_prompt_info_html = ""
if auto_save_imagery == 1:
additional_prompt_info_html = " The image, and a text file with generation information, will be saved automatically."
if use_xformers == 1:
from xformers.ops import MemoryEfficientAttentionFlashAttentionOp
if use_default_attn_processor == 1:
from diffusers.models.attention_processor import AttnProcessor
if (
default_base_model and
(default_base_model in base_model_object_of_model_configuration_arrays) and
(default_base_model in base_model_model_configuration_defaults_object)
):
default_model_configuration = base_model_model_configuration_defaults_object[default_base_model]
if default_model_configuration in model_configuration_names_object:
default_model_configuration_choices_array = []
for this_model_configuration in base_model_object_of_model_configuration_arrays[default_base_model]:
if model_configuration_names_object[this_model_configuration]:
default_model_configuration_choices_array.append(
model_configuration_names_object[this_model_configuration]
)
else:
error_function("A default configuration must be properly named in the code.")
else:
error_function("A default configuration must be properly configured in the code.")
else:
error_function("A default base model must be properly configured in the code.")
default_base_model_nicely_named_value = base_model_names_object[default_base_model]
default_model_configuration_nicely_named_value = model_configuration_names_object[default_model_configuration]
if enable_refiner != 1:
default_refiner_selected = 0
if enable_upscaler != 1:
default_upscaler_selected = 0
model_configuration_requires_refiner = 0
if default_model_configuration in model_configuration_force_refiner_object:
model_configuration_requires_refiner = model_configuration_force_refiner_object[default_model_configuration]
if model_configuration_requires_refiner == 1:
enable_refiner = 1
default_refiner_selected = 1
default_refine_option = "No"
if default_refiner_selected == 1:
default_refine_option = "Yes"
default_upscale_option = "No"
if default_upscaler_selected == 1:
default_upscale_option = "Yes"
is_default_config = 0
if default_model_configuration in default_model_configuration_object:
is_default_config = 1
default_refiner_and_upscaler_status_text = refiner_and_upscaler_status_opening_html
default_use_denoising_start_in_base_model_when_using_refiner_is_selected = False
if default_use_denoising_start_in_base_model_when_using_refiner == 1:
default_use_denoising_start_in_base_model_when_using_refiner_is_selected = True
default_base_model_output_to_refiner_is_in_latent_space_is_selected = False
if default_base_model_output_to_refiner_is_in_latent_space == 1:
default_base_model_output_to_refiner_is_in_latent_space_is_selected = True
refiner_default_config_accordion_visible = True
if (
(enable_refiner != 1) or
(is_default_config != 1)
):
refiner_default_config_accordion_visible = False
refiner_default_config_accordion_open = False
if (
(default_refiner_accordion_open == 1) or
(
(is_default_config == 1) and
(default_refiner_selected == 1)
)
):
refiner_default_config_accordion_open = True
refiner_online_config_accordion_visible = True
if (
(enable_refiner != 1) or
(is_default_config == 1)
):
refiner_online_config_accordion_visible = False
refiner_online_config_accordion_open = False
if (
(default_refiner_accordion_open == 1) or
(
(is_default_config != 1) and
(default_refiner_selected == 1)
)
):
refiner_online_config_accordion_open = True
refiner_group_visible = False
if enable_refiner == 1:
refiner_group_visible = True
if default_refiner_selected == 1:
default_refiner_and_upscaler_status_text += refiner_on_text
else:
default_refiner_and_upscaler_status_text += refiner_off_text
upscaler_accordion_open = False
if (
(default_upscaler_selected == 1) or
(default_upscaler_accordion_open == 1)
):
upscaler_accordion_open = True
upscaler_group_visible = False
if enable_upscaler == 1:
upscaler_group_visible = True
if default_upscaler_selected == 1:
default_refiner_and_upscaler_status_text += upscaler_on_text
else:
default_refiner_and_upscaler_status_text += upscaler_off_text
default_refiner_and_upscaler_status_text += refiner_and_upscaler_status_closing_html
image_gallery_array = []
prompt_information_array = []
default_negative_prompt_field_visibility = True
default_negative_prompt_for_sdxl_turbo_field_visibility = False
default_base_model_num_inference_steps_field_visibility = True
default_base_model_num_inference_steps_field_for_sdxl_turbo_field_visibility = False
default_guidance_scale_field_visibility = True
default_guidance_scale_for_sdxl_turbo_field_visibility = False
if default_base_model == "sdxl_turbo":
default_negative_prompt_field_visibility = False
default_negative_prompt_for_sdxl_turbo_field_visibility = True
default_base_model_num_inference_steps_field_visibility = False
default_base_model_num_inference_steps_field_for_sdxl_turbo_field_visibility = True
default_guidance_scale_field_visibility = False
default_guidance_scale_for_sdxl_turbo_field_visibility = True
last_model_configuration_name_value = ""
last_refiner_selected = ""
last_upscaler_selected = ""
if show_image_creation_progress_log == 1:
import time
current_progress_text = ""
current_actual_total_base_model_steps = ""
current_actual_total_refiner_steps = ""
current_actual_total_upscaler_steps = ""
default_base_model_choices_array = []
stored_model_configuration_names_object = {}
for this_base_model in base_model_array:
default_base_model_choices_array.append(
base_model_names_object[this_base_model]
)
stored_model_configuration = base_model_model_configuration_defaults_object[this_base_model]
stored_model_configuration_names_object[this_base_model] = model_configuration_names_object[stored_model_configuration]
###############################################################################
###############################################################################
#
#
#
#
#
#
# Functions
#
#
#
#
#
#
###############################################################################
###############################################################################
#####################
#
# Show Message
#
# Display message to user in model on web form and/or command prompt.
#
#####################
def show_message(
message_to_display
):
if show_messages_in_command_prompt == 1:
print (message_to_display)
if show_messages_in_modal_on_page == 1:
gr.Info(message_to_display)
#####################
#
# Convert Seconds
#
# Convert raw seconds to the numer of hours, minutes and seconds.
#
#####################
def convert_seconds(
seconds
):
# Google AI Code
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
return hours, minutes, seconds
#####################
#
# Seed Not Valid
#
# Return True if seed is not valid.
#
#####################
def seed_not_valid(seed_num_str):
try:
seed_num = int(seed_num_str)
if (seed_num > 0) and (seed_num <= default_seed_maximum):
return False
else:
return True
except ValueError:
return True
#####################
#
# Numerical Bool
#
# Return 1 for anything that is True/Yes/1. Everything else is False.
#
#####################
def numerical_bool(
original_value
):
new_value = 0
if (
(original_value == 1) or
(original_value == "Yes") or
(original_value == "True") or
(original_value == True)
):
new_value = 1
return new_value
#####################
#
# Truncate Prompt
#
# Truncate a prompt. Get the actual prompt that will be used and save the
# part of the prompt that will not be used.
#
#####################
def truncate_prompt (
existing_prompt_text
):
# Only 77 tokens are allowed in the prompt. 2 are reserved, meaning it is
# truncated to 75. This happens automatically, but we want to tell people
# that
tokenizer = pipe.tokenizer
max_token_length_of_model = pipe.tokenizer.model_max_length - number_of_reserved_tokens
prompt_text_words_array = existing_prompt_text.split(" ")
prompt_text_words_array_length = len(prompt_text_words_array)
prompt_text_words_index = 0
prompt_text_substring = ""
prompt_text_not_used_substring = ""
for prompt_text_word in prompt_text_words_array:
prompt_text_words_index += 1
substring_to_test = prompt_text_substring
if prompt_text_words_index > 1:
substring_to_test += " "
substring_to_test += prompt_text_word
token_length_of_substring_to_test = len(tokenizer.tokenize(substring_to_test))
if token_length_of_substring_to_test > max_token_length_of_model:
prompt_text_not_used_substring += prompt_text_word + " "
else:
prompt_text_substring = substring_to_test
return (
prompt_text_substring,
prompt_text_not_used_substring
)
#####################
#
# Update Prompt Info From Gallery
#
# If you select an image in the image gallery, display the prompt
# information for that image.
#
#####################
def update_prompt_info_from_gallery (
gallery_data: gr.SelectData
):
gallery_data_index = gallery_data.index
output_image_field_update = gr.Gallery(
selected_index = gallery_data_index
)
output_text_field_update = prompt_information_array[gallery_data_index]
return {
output_image_field: output_image_field_update,
output_text_field: output_text_field_update
}
#####################
#
# Callback Function for Base Model Progress
#
# Add the current step the generation is on in the base model to the web
# interface.
#
#####################
def callback_function_for_base_model_progress(
callback_pipe,
callback_step_index,
callback_timestep,
callback_kwargs
):
global current_progress_text
global current_base_model_generation_start_time
current_progress_text = "Base model steps complete... " + str(callback_step_index) + " of " + str(current_actual_total_base_model_steps)
if int(callback_step_index) == 0:
current_base_model_generation_start_time = time.time()
if int(callback_step_index) > 0:
seconds_per_step = ((time.time() - current_base_model_generation_start_time) / int(callback_step_index))
(
time_per_step_hours,
time_per_step_minutes,
time_per_step_seconds
) = convert_seconds(seconds_per_step)
if time_per_step_hours > 0:
hours_text = "hr"
if time_per_step_hours > 1:
hours_text = "hrs"
nice_time_per_step = str(int(time_per_step_hours)) + " " + hours_text + ". " + str(int(time_per_step_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
elif time_per_step_minutes > 0:
nice_time_per_step = str(int(time_per_step_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
else:
nice_time_per_step = str(round(time_per_step_seconds, 2)) + " sec."
current_progress_text += "\n" + nice_time_per_step + " per step"
return {}
#####################
#
# Callback Function for Refiner Progress
#
# Add the current step the generation is on in the refiner to the web
# interface.
#
#####################
def callback_function_for_refiner_progress(
callback_pipe,
callback_step_index,
callback_timestep,
callback_kwargs
):
global current_progress_text
global current_refiner_generation_start_time
current_progress_text = "Refiner steps complete... " + str(callback_step_index) + " of " + str(current_actual_total_refiner_steps)
if int(callback_step_index) == 0:
current_refiner_generation_start_time = time.time()
if int(callback_step_index) > 0:
seconds_per_step = ((time.time() - current_refiner_generation_start_time) / int(callback_step_index))
(
time_per_step_hours,
time_per_step_minutes,
time_per_step_seconds
) = convert_seconds(seconds_per_step)
if time_per_step_hours > 0:
hours_text = "hr"
if time_per_step_hours > 1:
hours_text = "hrs"
nice_time_per_step = str(int(time_per_step_hours)) + " " + hours_text + ". " + str(int(time_per_step_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
elif time_per_step_minutes > 0:
nice_time_per_step = str(int(time_per_step_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
else:
nice_time_per_step = str(round(time_per_step_seconds, 2)) + " sec."
current_progress_text += "\n" + nice_time_per_step + " per step"
return {}
#####################
#
# Update Log Progress
#
# This is called every second when "show_image_creation_progress_log" is
# set to 1. It displays the latest value in "current_progress_text".
#
#####################
def update_log_progress ():
global current_progress_text
log_text_field_update = gr.Textbox(
value = current_progress_text
)
return {
log_text_field: log_text_field_update
}
#####################
#
# Toggle Interactivity During Image Creation
#
#
#
#####################
def toggle_interactivity_during_image_creation (
interactivity
):
if script_being_run_on_hugging_face == 1:
prompt_field_update = gr.Textbox(
interactive = interactivity,
)
negative_prompt_field_update = gr.Textbox(
interactive = interactivity
)
else:
prompt_field_update = gr.Textbox()
negative_prompt_field_update = gr.Textbox()
refining_selection_default_config_field_update = gr.Radio(
interactive = interactivity
)
refining_denoise_start_for_default_config_field_update = gr.Slider(
interactive = interactivity
)
refining_use_denoising_start_in_base_model_when_using_refiner_field_update = gr.Checkbox(
interactive = interactivity
)
refining_base_model_output_to_refiner_is_in_latent_space_field_update = gr.Checkbox(
interactive = interactivity
)
refining_selection_online_config_normal_field_update = gr.Radio(
interactive = interactivity
)
refining_selection_online_config_automatically_selected_field_update = gr.Radio(
interactive = interactivity
)
refining_denoise_start_for_online_config_field_update = gr.Slider(
interactive = interactivity
)
refining_number_of_iterations_for_online_config_field_update = gr.Slider(
interactive = interactivity
)
upscaling_selection_field_update = gr.Radio(
interactive = interactivity
)
upscaling_num_inference_steps_field_update = gr.Slider(
interactive = interactivity
)
base_model_field_update = gr.Dropdown(
interactive = interactivity
)
model_configuration_field_update = gr.Dropdown(
interactive = interactivity
)
image_width_field_update = gr.Slider(
interactive = interactivity
)
image_height_field_update = gr.Slider(
interactive = interactivity
)
base_model_num_inference_steps_field_update = gr.Slider(
interactive = interactivity
)
base_model_num_inference_steps_field_for_sdxl_turbo_field_update = gr.Slider(
interactive = interactivity
)
guidance_scale_field_update = gr.Slider(
interactive = interactivity
)
if make_seed_selection_a_textbox == 1:
seed_field_update = gr.Textbox(
interactive = interactivity
)
else:
seed_field_update = gr.Slider(
interactive = interactivity
)
return {
prompt_field: prompt_field_update,
negative_prompt_field: negative_prompt_field_update,
refining_selection_default_config_field: refining_selection_default_config_field_update,
refining_denoise_start_for_default_config_field: refining_denoise_start_for_default_config_field_update,
refining_use_denoising_start_in_base_model_when_using_refiner_field: refining_use_denoising_start_in_base_model_when_using_refiner_field_update,
refining_base_model_output_to_refiner_is_in_latent_space_field: refining_base_model_output_to_refiner_is_in_latent_space_field_update,
refining_selection_online_config_normal_field: refining_selection_online_config_normal_field_update,
refining_selection_online_config_automatically_selected_field: refining_selection_online_config_automatically_selected_field_update,
refining_denoise_start_for_online_config_field: refining_denoise_start_for_online_config_field_update,
refining_number_of_iterations_for_online_config_field: refining_number_of_iterations_for_online_config_field_update,
upscaling_selection_field: upscaling_selection_field_update,
upscaling_num_inference_steps_field: upscaling_num_inference_steps_field_update,
base_model_field: base_model_field_update,
model_configuration_field: model_configuration_field_update,
image_width_field: image_width_field_update,
image_height_field: image_height_field_update,
base_model_num_inference_steps_field: base_model_num_inference_steps_field_update,
base_model_num_inference_steps_field_for_sdxl_turbo_field: base_model_num_inference_steps_field_for_sdxl_turbo_field_update,
guidance_scale_field: guidance_scale_field_update,
seed_field: seed_field_update
}
#####################
#
# Before Create Image Function
#
# This is loaded before the image creation begins.
#
#####################
def before_create_image_function ():
generate_image_btn_update = gr.Button(
value = "Generating...",
variant = "secondary",
interactive = False
)
output_text_field_update = gr.Textbox(
visible = False
)
log_text_field_update = gr.Textbox(
value = "",
visible = True,
every = 1
)
# toggled_interactivity_fields_kwargs = toggle_interactivity_during_image_creation(False)
toggled_interactivity_fields_kwargs = {}
return {
generate_image_btn: generate_image_btn_update,
output_text_field: output_text_field_update,
log_text_field: log_text_field_update,
**toggled_interactivity_fields_kwargs
}
#####################
#
# After Create Image Function
#
# This is loaded once image creation has completed.
#
#####################
def after_create_image_function ():
generate_image_btn_update = gr.Button(
value = "Generate",
variant = "primary",
interactive = True
)
output_text_field_update = gr.Textbox(
visible = True
)
log_text_field_update = gr.Textbox(
value = "",
visible = False,
every = None
)
# toggled_interactivity_fields_kwargs = toggle_interactivity_during_image_creation(True)
toggled_interactivity_fields_kwargs = {}
return {
generate_image_btn: generate_image_btn_update,
output_text_field: output_text_field_update,
log_text_field: log_text_field_update,
**toggled_interactivity_fields_kwargs
}
#####################
#
# Create Image Function
#
# This is the main image creation function.
#
#####################
def create_image_function (
base_model_field_index,
model_configuration_field_index,
prompt_text,
negative_prompt_text,
image_width,
image_height,
guidance_scale,
base_model_num_inference_steps,
base_model_num_inference_steps_field_for_sdxl_turbo,
actual_seed,
refining_selection_default_config_field_value,
refining_selection_online_config_normal_field_value,
refining_selection_online_config_automatically_selected_field_value,
refining_denoise_start_for_default_config_field_value,
refining_use_denoising_start_in_base_model_when_using_refiner_field_value,
refining_base_model_output_to_refiner_is_in_latent_space_field_value,
refining_denoise_start_for_online_config_field_value,
refining_number_of_iterations_for_online_config_field_value,
upscaling_selection_field_value,
upscaling_num_inference_steps
):
global current_progress_text
global current_actual_total_base_model_steps
global current_actual_total_refiner_steps
current_progress_text = ""
current_actual_total_base_model_steps = 0
current_actual_total_refiner_steps = 0
current_actual_total_upscaler_steps = 0
refining_selection_default_config_field_value = numerical_bool(refining_selection_default_config_field_value)
refining_selection_online_config_normal_field_value = numerical_bool(refining_selection_online_config_normal_field_value)
refining_selection_online_config_automatically_selected_field_value = numerical_bool(refining_selection_online_config_automatically_selected_field_value)
refining_use_denoising_start_in_base_model_when_using_refiner_field_value = numerical_bool(refining_use_denoising_start_in_base_model_when_using_refiner_field_value)
refining_base_model_output_to_refiner_is_in_latent_space_field_value = numerical_bool(refining_base_model_output_to_refiner_is_in_latent_space_field_value)
use_upscaler = numerical_bool(upscaling_selection_field_value)
base_model_name_value = base_model_array[base_model_field_index]
model_configuration_name_value = base_model_object_of_model_configuration_arrays[base_model_name_value][model_configuration_field_index]
current_actual_total_base_model_steps = base_model_num_inference_steps
current_actual_total_upscaler_steps = upscaling_num_inference_steps
is_default_config_state = 0
if model_configuration_name_value in default_model_configuration_object:
is_default_config_state = 1
use_refiner = 0
if (
(
(is_default_config_state == 1) and
refining_selection_default_config_field_value
) or (
(is_default_config_state != 1) and
(
(
(model_configuration_name_value not in model_configuration_force_refiner_object) and
refining_selection_online_config_normal_field_value
) or (
(model_configuration_name_value in model_configuration_force_refiner_object) and
refining_selection_online_config_automatically_selected_field_value
)
)
)
):
use_refiner = 1
if base_model_name_value == "sdxl_turbo":
negative_prompt_text = ""
base_model_num_inference_steps = base_model_num_inference_steps_field_for_sdxl_turbo
current_actual_total_base_model_steps = base_model_num_inference_steps
guidance_scale = 0
global last_model_configuration_name_value
global pipe
global refiner
global upscaler
global image_gallery_array
global prompt_information_array
if (
(last_model_configuration_name_value == "") or
(model_configuration_name_value != last_model_configuration_name_value)
):
current_progress_text = "Base model is loading."
show_message(current_progress_text)
if (last_model_configuration_name_value != ""):
# del pipe
if 'pipe' in globals():
del pipe
if 'refiner' in globals():
del refiner
if 'upscaler' in globals():
del upscaler
import gc
gc.collect()
if device == "cuda":
torch.cuda.empty_cache()
if base_model_name_value == "photoreal":
base_model_kwargs = {
"safety_checker": None,
"requires_safety_checker": False
}
elif base_model_name_value == "sdxl_turbo":
base_model_kwargs = {
"use_safetensors": True,
"safety_checker": None
}
if device == "cuda":
base_model_kwargs["variant"] = "fp16"
else:
base_model_kwargs = {
"use_safetensors": True
}
if device == "cuda":
base_model_kwargs["variant"] = "fp16"
if device == "cuda":
base_model_kwargs["torch_dtype"] = torch.float16
if use_custom_hugging_face_cache_dir == 1:
base_model_kwargs["cache_dir"] = hugging_face_cache_dir
pipe = DiffusionPipeline.from_pretrained(
model_configuration_links_object[model_configuration_name_value],
**base_model_kwargs
)
if use_model_cpu_offload_for_base_model == 1:
pipe.enable_model_cpu_offload()
if use_xformers == 1:
pipe.enable_xformers_memory_efficient_attention()
pipe = pipe.to(device)
if use_sequential_cpu_offload_for_base_model == 1:
pipe.enable_sequential_cpu_offload()
if use_default_attn_processor == 1:
pipe.unet.set_default_attn_processor()
if device == "cuda":
torch.cuda.empty_cache()
else:
pipe.unet = torch.compile(
pipe.unet,
mode = "reduce-overhead",
fullgraph = True
)
last_model_configuration_name_value = model_configuration_name_value
if use_refiner == 1:
current_progress_text = "Refiner is loading."
show_message(current_progress_text)
refiner_kwargs = {
"use_safetensors": True
}
if device == "cuda":
refiner_kwargs["variant"] = "fp16"
refiner_kwargs["torch_dtype"] = torch.float16
if use_custom_hugging_face_cache_dir == 1:
refiner_kwargs["cache_dir"] = hugging_face_cache_dir
refiner = DiffusionPipeline.from_pretrained(
hugging_face_refiner_partial_path,
**refiner_kwargs
)
if use_model_cpu_offload_for_refiner == 1:
refiner.enable_model_cpu_offload()
if use_xformers == 1:
refiner.enable_xformers_memory_efficient_attention()
refiner = refiner.to(device)
if use_sequential_cpu_offload_for_refiner == 1:
refiner.enable_sequential_cpu_offload()
if use_default_attn_processor == 1:
refiner.unet.set_default_attn_processor()
if device == "cuda":
torch.cuda.empty_cache()
else:
refiner.unet = torch.compile(
refiner.unet,
mode = "reduce-overhead",
fullgraph = True
)
if use_upscaler == 1:
current_progress_text = "Upscaler is loading."
show_message(current_progress_text)
upscaler_kwargs = {
"use_safetensors": True
}
if device == "cuda":
upscaler_kwargs["torch_dtype"] = torch.float16
if use_custom_hugging_face_cache_dir == 1:
upscaler_kwargs["cache_dir"] = hugging_face_cache_dir
upscaler = DiffusionPipeline.from_pretrained(
hugging_face_upscaler_partial_path,
**upscaler_kwargs
)
if use_model_cpu_offload_for_upscaler == 1:
upscaler.enable_model_cpu_offload()
if use_xformers == 1:
upscaler.enable_xformers_memory_efficient_attention()
upscaler = upscaler.to(device)
if use_sequential_cpu_offload_for_upscaler == 1:
upscaler.enable_sequential_cpu_offload()
if use_default_attn_processor == 1:
upscaler.unet.set_default_attn_processor()
if device == "cuda":
torch.cuda.empty_cache()
else:
upscaler.unet = torch.compile(
upscaler.unet,
mode = "reduce-overhead",
fullgraph = True
)
if log_generation_times == 1:
start_time = time.time()
# Only 77 tokens are allowed in the prompt. 2 are reserved, meaning it is
# truncated to 75. This happens automatically, but we want to tell people
# that
tokenizer = pipe.tokenizer
max_token_length_of_model = pipe.tokenizer.model_max_length - number_of_reserved_tokens
token_length_of_prompt_text = len(tokenizer.tokenize(prompt_text))
token_length_of_negative_prompt_text = len(tokenizer.tokenize(negative_prompt_text))
prompt_text_not_used_substring = ""
message_about_prompt_truncation = ""
if token_length_of_prompt_text > max_token_length_of_model:
(
prompt_text,
prompt_text_not_used_substring
) = truncate_prompt(
prompt_text
)
message_about_prompt_truncation += "Your prompt has been truncated because it is too long. This part has been truncated:<br/><br/><span style=\"font-style: italic;\">" + prompt_text_not_used_substring + "</span>"
negative_prompt_text_not_used_substring = ""
if token_length_of_negative_prompt_text > max_token_length_of_model:
(
negative_prompt_text,
negative_prompt_text_not_used_substring
) = truncate_prompt(
negative_prompt_text
)
if len(message_about_prompt_truncation) > 0:
message_about_prompt_truncation += "<br/><br/>"
message_about_prompt_truncation += "Your negative prompt has been truncated because it is too long. This part has been truncated:<br/><br/><span style=\"font-style: italic;\">" + negative_prompt_text_not_used_substring + "</span>"
prompt_truncated_field_udpate = gr.HTML(
value = "",
visible = False
)
if len(message_about_prompt_truncation) > 0:
prompt_truncated_field_udpate = gr.HTML(
value = "<div style=\"padding: 10px; background: #fff;\"><span style=\"font-weight: bold;\">Note</span>: " + message_about_prompt_truncation + "</div>",
visible = True
)
show_message("Note: Part of your prompt has been truncated automatically because it was too long.")
actual_seed = int(actual_seed)
if actual_seed == 0:
import random
default_seed_maximum_for_random = default_seed_maximum
if default_seed_maximum_for_random > 9007199254740992:
# If above this number, seeds may not be able to be entered into slider properly.
default_seed_maximum_for_random = 9007199254740992
actual_seed = int(random.randrange(1, 10**len(str(default_seed_maximum))))
if seed_not_valid(actual_seed):
raise Exception("Seed is not valid.")
generator = torch.manual_seed(actual_seed)
if show_image_creation_progress_log == 1:
callback_to_do_for_base_model_progress = callback_function_for_base_model_progress
callback_to_do_for_refiner_progress = callback_function_for_refiner_progress
else:
callback_to_do_for_base_model_progress = None
callback_to_do_for_refiner_progress = None
if model_configuration_name_value.find("default") < 0:
#
#
#
# Attempt To Match Online Configurations
#
#
#
prompt = prompt_text
negative_prompt = negative_prompt_text
width = image_width
height = image_height
scale = guidance_scale
steps = base_model_num_inference_steps
refining = use_refiner
if refining == 1:
refining = "Yes"
upscaling = use_upscaler
if upscaling == 1:
upscaling = "Yes"
prompt_2 = ""
negative_prompt_2 = ""
high_noise_frac = refining_denoise_start_for_online_config_field_value
if (
model_configuration_name_value == "sdxl_2023-11-12" or
model_configuration_name_value == "sdxl_2023-09-05"
):
n_steps = refining_number_of_iterations_for_online_config_field_value
upscaling_num_inference_steps = 15
if model_configuration_name_value == "sdxl_2023-09-05":
upscaling_num_inference_steps = 5
current_actual_total_upscaler_steps = upscaling_num_inference_steps
if show_messages_in_command_prompt == 1:
print ("Initial image creation has begun.");
if show_image_creation_progress_log == 1:
current_progress_text = "Initial image creation has begun."
int_image = pipe(
prompt,
prompt_2=prompt_2,
negative_prompt=negative_prompt,
negative_prompt_2=negative_prompt_2,
num_inference_steps=steps,
height=height,
width=width,
guidance_scale=scale,
num_images_per_prompt=1,
generator=generator,
output_type="latent",
callback_on_step_end=callback_to_do_for_base_model_progress
).images
if show_messages_in_command_prompt == 1:
print ("Refiner steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Refining is beginning."
current_actual_total_refiner_steps = int(int(n_steps) * float(high_noise_frac))
nice_refiner_denoise_start = str(refining_denoise_start_for_online_config_field_value)
refiner_info_for_info_about_prompt_lines_array = [
"Refiner? Yes"
"Refiner denoise start %: " + nice_refiner_denoise_start,
"Refiner number of iterations: " + str(refining_number_of_iterations_for_online_config_field_value),
"Actual Refining Steps: " + str(current_actual_total_refiner_steps)
]
image = refiner(
prompt=prompt,
prompt_2=prompt_2,
negative_prompt=negative_prompt,
negative_prompt_2=negative_prompt_2,
image=int_image,
num_inference_steps=n_steps,
denoising_start=high_noise_frac,
callback_on_step_end=callback_to_do_for_refiner_progress
).images[0]
if upscaling == 'Yes':
if show_messages_in_command_prompt == 1:
print ("Upscaler steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Upscaling in progress.\n(step by step progress not displayed)"
# Changed
#
# num_inference_steps=15
#
upscaled = upscaler(
prompt=prompt,
negative_prompt=negative_prompt,
image=image,
num_inference_steps=upscaling_num_inference_steps,
guidance_scale=0
).images[0]
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = upscaled
else:
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = image
elif (
model_configuration_name_value == "photoreal_2023-11-12" or
model_configuration_name_value == "photoreal_2023-09-01"
):
Prompt = prompt
upscale = refining # Not a mistake. This is wrong in code.
if upscale == "Yes":
if show_messages_in_command_prompt == 1:
print ("Initial image creation has begun.");
if show_image_creation_progress_log == 1:
current_progress_text = "Initial image creation has begun."
int_image = pipe(
Prompt,
negative_prompt=negative_prompt,
height=height,
width=width,
num_inference_steps=steps,
guidance_scale=scale,
callback_on_step_end=callback_to_do_for_base_model_progress
).images
if show_messages_in_command_prompt == 1:
print ("Refiner steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Refining is beginning."
default_steps_in_diffusers = 50
current_actual_total_refiner_steps = int(default_steps_in_diffusers * float(high_noise_frac))
refiner_info_for_info_about_prompt_lines_array = [
"Refiner? Yes"
"Refiner denoise start %: " + nice_refiner_denoise_start,
"Refiner number of iterations: " + str(current_actual_total_refiner_steps),
"Actual Refining Steps: " + str(current_actual_total_refiner_steps)
]
image = refiner(
Prompt,
negative_prompt=negative_prompt,
image=int_image,
num_inference_steps=default_steps_in_diffusers,
denoising_start=high_noise_frac,
callback_on_step_end=callback_to_do_for_refiner_progress
).images[0]
else:
if show_messages_in_command_prompt == 1:
print ("Image creation has begun.");
if show_image_creation_progress_log == 1:
current_progress_text = "Image creation has begun."
image = pipe(
Prompt,
negative_prompt=negative_prompt,
height=height,
width=width,
num_inference_steps=steps,
guidance_scale=scale,
callback_on_step_end=callback_to_do_for_base_model_progress
).images[0]
image_to_return = image
else:
#
#
#
# My Configurations
#
#
#
if use_refiner == 1:
if refining_use_denoising_start_in_base_model_when_using_refiner_field_value == 1:
denoising_end = refining_denoise_start_for_default_config_field_value
current_actual_total_base_model_steps = int(base_model_num_inference_steps * float(refining_denoise_start_for_default_config_field_value))
else:
denoising_end = None
output_type_before_refiner = "pil"
if refining_base_model_output_to_refiner_is_in_latent_space_field_value == 1:
output_type_before_refiner = "latent"
current_actual_total_refiner_steps = (base_model_num_inference_steps - int(base_model_num_inference_steps * float(refining_denoise_start_for_default_config_field_value)))
refiner_info_for_info_about_prompt_lines_array = [
"Refiner? Yes"
]
nice_refiner_denoise_start = str(refining_denoise_start_for_online_config_field_value)
if refining_use_denoising_start_in_base_model_when_using_refiner_field_value == 1:
refiner_info_for_info_about_prompt_lines_array.extend([
"Set \"denoising_end\" in base model generation? Yes",
"Base model denoise end %: " + nice_refiner_denoise_start,
"Actual Base Model Steps: " + str(current_actual_total_base_model_steps)
])
else:
refiner_info_for_info_about_prompt_lines_array.extend([
"Set \"denoising_end\" in base model generation? No",
])
refiner_info_for_info_about_prompt_lines_array.extend([
"Refiner denoise start %: " + nice_refiner_denoise_start,
"Actual Refining Steps: " + str(current_actual_total_refiner_steps)
])
if refining_base_model_output_to_refiner_is_in_latent_space_field_value == 1:
refiner_info_for_info_about_prompt_lines_array.extend([
"Base model output in latent space before refining? Yes",
])
else:
refiner_info_for_info_about_prompt_lines_array.extend([
"Base model output in latent space before refining? No",
])
if use_upscaler == 1:
if show_messages_in_command_prompt == 1:
print ("Will create initial image, then refine and then upscale.");
print ("Initial image steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Initial image creation has begun."
intitial_image = pipe(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
width = image_width,
height = image_height,
num_inference_steps = base_model_num_inference_steps,
guidance_scale = guidance_scale,
num_images_per_prompt = 1,
generator = generator,
denoising_end = denoising_end,
output_type = output_type_before_refiner,
callback_on_step_end = callback_to_do_for_base_model_progress
).images
if show_messages_in_command_prompt == 1:
print ("Refiner steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Refining is beginning."
refined_image = refiner(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
image = intitial_image,
num_inference_steps = base_model_num_inference_steps,
denoising_start = refining_denoise_start_for_default_config_field_value,
output_type = "pil",
callback_on_step_end = callback_to_do_for_refiner_progress
).images
if show_messages_in_command_prompt == 1:
print ("Upscaler steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Upscaling in progress.\n(step by step progress not displayed)"
upscaled_image = upscaler(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
image = refined_image,
num_inference_steps = upscaling_num_inference_steps,
guidance_scale = 0
).images[0]
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = upscaled_image
else:
if show_messages_in_command_prompt == 1:
print ("Will create initial image and then refine.");
print ("Initial image steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Initial image creation has begun."
intitial_image = pipe(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
width = image_width,
height = image_height,
num_inference_steps = base_model_num_inference_steps,
guidance_scale = guidance_scale,
num_images_per_prompt = 1,
generator = generator,
denoising_end = denoising_end,
output_type = output_type_before_refiner,
callback_on_step_end = callback_to_do_for_base_model_progress
).images
if show_messages_in_command_prompt == 1:
print ("Refiner steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Refining is beginning."
refined_image = refiner(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
image = intitial_image,
num_inference_steps = base_model_num_inference_steps,
denoising_start = refining_denoise_start_for_default_config_field_value,
callback_on_step_end = callback_to_do_for_refiner_progress
).images[0]
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = refined_image
else:
if use_upscaler == 1:
if show_messages_in_command_prompt == 1:
print ("Will create initial image and then upscale.");
print ("Initial image steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Initial image creation has begun."
intitial_image = pipe(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
width = image_width,
height = image_height,
num_inference_steps = base_model_num_inference_steps,
guidance_scale = guidance_scale,
num_images_per_prompt = 1,
generator = generator,
output_type = "pil",
callback_on_step_end = callback_to_do_for_base_model_progress
).images
if show_messages_in_command_prompt == 1:
print ("Upscaler steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Upscaling in progress.\n(step by step progress not displayed)"
upscaled_image = upscaler(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
image = intitial_image,
num_inference_steps = upscaling_num_inference_steps,
guidance_scale = 0
).images[0]
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = upscaled_image
else:
if show_messages_in_command_prompt == 1:
print ("Will create image (no refining or upscaling).");
print ("Image steps...");
if show_image_creation_progress_log == 1:
current_progress_text = "Image creation has begun."
image = pipe(
prompt = prompt_text,
negative_prompt = negative_prompt_text,
width = image_width,
height = image_height,
num_inference_steps = base_model_num_inference_steps,
guidance_scale = guidance_scale,
num_images_per_prompt = 1,
generator = generator,
callback_on_step_end = callback_to_do_for_base_model_progress
).images[0]
if device == "cuda":
torch.cuda.empty_cache()
image_to_return = image
#
#
#
# Prompt Information
#
#
#
nice_model_name = base_model_names_object[base_model_name_value] + " (" + model_configuration_links_object[model_configuration_name_value] + ")"
info_about_prompt_lines_array = [
"Prompt:\n" + prompt_text
]
if len(negative_prompt_text) > 0:
info_about_prompt_lines_array.extend([
"Negative Prompt:\n" + negative_prompt_text
])
dimensions_title = "Dimensions"
if use_upscaler == 1:
dimensions_title = "Original Dimensions"
info_about_prompt_lines_array.extend([
dimensions_title + ": " + str(image_width) + "x" + str(image_height) + " px"
])
if use_upscaler == 1:
upscaled_image_width = int(image_width * 2)
upscaled_image_height = int(image_height * 2)
info_about_prompt_lines_array.extend([
"Upscaled Dimensions: " + str(upscaled_image_width) + "x" + str(upscaled_image_height) + " px"
])
info_about_prompt_lines_array.extend([
"Seed: " + str(actual_seed)
])
if int(guidance_scale) > 0:
info_about_prompt_lines_array.extend([
"Guidance Scale: " + str(guidance_scale)
])
info_about_prompt_lines_array.extend([
"Steps: " + str(base_model_num_inference_steps),
"Model: " + nice_model_name
])
if use_refiner == 1:
# Default Configuration
info_about_prompt_lines_array.extend(refiner_info_for_info_about_prompt_lines_array)
if use_upscaler == 1:
info_about_prompt_lines_array.extend([
"Upscaled (2x)? Yes",
"Refiner Steps: " + str(upscaling_num_inference_steps)
])
if log_generation_times == 1:
end_time = time.time()
generation_time_in_seconds = (end_time - start_time)
(
generation_partial_hours,
generation_partial_minutes,
generation_partial_seconds
) = convert_seconds(generation_time_in_seconds)
if generation_partial_hours > 0:
hours_text = "hr"
if generation_partial_hours > 1:
hours_text = "hrs"
nice_generation_time = str(int(generation_partial_hours)) + " " + hours_text + ". " + str(int(generation_partial_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
elif generation_partial_minutes > 0:
nice_generation_time = str(int(generation_partial_minutes)) + " min. " + str(round(generation_partial_seconds, 1)) + " sec."
else:
nice_generation_time = str(round(generation_time_in_seconds, 2)) + " sec."
info_about_prompt_lines_array.extend([
"Time: " + nice_generation_time
])
if len(prompt_text_not_used_substring) > 0:
info_about_prompt_lines_array.extend([
"End of Prompt Truncated: " + prompt_text_not_used_substring
])
if len(negative_prompt_text_not_used_substring) > 0:
info_about_prompt_lines_array.extend([
"End of Negative Prompt Truncated: " + negative_prompt_text_not_used_substring
])
if display_xformers_usage_in_prompt_info > 0:
nice_xformers_usage = "No"
if use_xformers == 1:
nice_xformers_usage = "Yes"
if include_transformers_version_in_prompt_info == 1:
import transformers
nice_xformers_usage += " (version " + str(transformers.__version__) + ")"
info_about_prompt_lines_array.extend([
"xFormers Used?: " + nice_xformers_usage
])
if display_default_attn_processor_usage_in_prompt_info > 0:
nice_default_attn_processor_usage = "No"
if use_default_attn_processor == 1:
nice_default_attn_processor_usage = "Yes"
info_about_prompt_lines_array.extend([
"Default AttnProcessor Used?: " + nice_default_attn_processor_usage
])
info_about_prompt = '\n'.join(info_about_prompt_lines_array)
if auto_save_imagery == 1:
if not os.path.exists(saved_images_dir):
os.makedirs(saved_images_dir)
yy_mm_dd_date_stamp = datetime.today().strftime('%Y-%m-%d')
saved_images_date_dir = saved_images_dir + "/" + yy_mm_dd_date_stamp + "/"
if not os.path.exists(saved_images_date_dir):
os.makedirs(saved_images_date_dir)
image_count = 1
file_name_without_extension = yy_mm_dd_date_stamp + "-" + ('%04d' % image_count)
saved_image_path_and_file = saved_images_date_dir + file_name_without_extension + ".png"
while os.path.exists(saved_image_path_and_file):
file_name_without_extension = yy_mm_dd_date_stamp + "-" + ('%04d' % image_count)
saved_image_path_and_file = saved_images_date_dir + file_name_without_extension + ".png"
image_count += 1
image_to_return_file = image_to_return.save(saved_image_path_and_file)
saved_text_file_path_and_file = saved_images_date_dir + file_name_without_extension + ".txt"
prompt_info_file_handle = open(saved_text_file_path_and_file, "w")
prompt_info_file_handle.writelines(info_about_prompt)
prompt_info_file_handle.close()
if use_image_gallery == 1:
image_gallery_array.insert(0, image_to_return)
prompt_information_array.insert(0, info_about_prompt)
output_image_field_update = gr.Gallery(
value = image_gallery_array,
selected_index = 0
)
else:
output_image_field_update = gr.Image(
value = image_to_return
)
if show_messages_in_command_prompt == 1:
print ("Image created.")
return {
output_image_field: output_image_field_update,
output_text_field: info_about_prompt,
prompt_truncated_field: prompt_truncated_field_udpate
}
#####################
#
# Cancel Image Processing
#
# When running on Windows, this is an attempt at closing the command
# prompt from the web display. It's really not worth having this. You can
# just close the prompt. I would like a nice way to cancel image
# creation, but couldn't figure that out.
#
#####################
def cancel_image_processing():
# I simply don't know how to stop the image generation without closing
# the command prompt. Doing that requires the code below twice for some
# reason.
#
# Method:
# https://stackoverflow.com/questions/67146623/how-to-close-the-command-prompt-from-python-script-directly
gr.Warning("The command prompt window has been closed. Any image generation in progress has been stopped. To generate any other images, you will need to launch the command prompt again.")
os.system('title kill_window')
os.system(f'taskkill /f /fi "WINDOWTITLE eq kill_window"')
os.system(f'taskkill /f /fi "WINDOWTITLE eq kill_window"')
#####################
#
# Base Model Field Update Function
#
# When the base model dropdown changes, this function is run.
#
#####################
def base_model_field_update_function(
base_model_field_index
):
base_model_field_value = base_model_array[base_model_field_index]
if base_model_field_value in base_model_array:
if base_model_field_value in base_model_object_of_model_configuration_arrays:
model_configuration_choices_array_update = []
for this_model_configuration in base_model_object_of_model_configuration_arrays[base_model_field_value]:
model_configuration_choices_array_update.append(
model_configuration_names_object[this_model_configuration]
)
if base_model_field_value in base_model_model_configuration_defaults_object:
model_configuration_field_selected_value = stored_model_configuration_names_object[base_model_field_value]
model_configuration_field_update = gr.Dropdown(
choices = model_configuration_choices_array_update,
value = model_configuration_field_selected_value
)
negative_prompt_field_visibility = True
negative_prompt_for_sdxl_turbo_field_visibility = False
base_model_num_inference_steps_field_visibility = True
base_model_num_inference_steps_field_for_sdxl_turbo_visibility = False
guidance_scale_field_visibility = True
guidance_scale_for_sdxl_turbo_field_visibility = False
if base_model_field_value == "sdxl_turbo":
negative_prompt_field_visibility = False
negative_prompt_for_sdxl_turbo_field_visibility = True
base_model_num_inference_steps_field_visibility = False
base_model_num_inference_steps_field_for_sdxl_turbo_visibility = True
guidance_scale_field_visibility = False
guidance_scale_for_sdxl_turbo_field_visibility = True
negative_prompt_field_update = gr.Textbox(
visible = negative_prompt_field_visibility
)
negative_prompt_for_sdxl_turbo_field_update = gr.HTML(
visible = negative_prompt_for_sdxl_turbo_field_visibility
)
base_model_num_inference_steps_field_update = gr.Slider(
visible = base_model_num_inference_steps_field_visibility
)
base_model_num_inference_steps_field_for_sdxl_turbo_update = gr.Slider(
visible = base_model_num_inference_steps_field_for_sdxl_turbo_visibility
)
guidance_scale_field_update = gr.Slider(
visible = guidance_scale_field_visibility
)
guidance_scale_for_sdxl_turbo_field_update = gr.HTML(
visible = guidance_scale_for_sdxl_turbo_field_visibility
)
return {
model_configuration_field: model_configuration_field_update,
negative_prompt_field: negative_prompt_field_update,
negative_prompt_for_sdxl_turbo_field: negative_prompt_for_sdxl_turbo_field_update,
base_model_num_inference_steps_field: base_model_num_inference_steps_field_update,
base_model_num_inference_steps_field_for_sdxl_turbo_field: base_model_num_inference_steps_field_for_sdxl_turbo_update,
guidance_scale_field: guidance_scale_field_update,
guidance_scale_for_sdxl_turbo_field: guidance_scale_for_sdxl_turbo_field_update
}
error_function("Error")
#####################
#
# Model Configuration Field Update Function
#
# When the model configuration dropdown changes, this function is run.
#
#####################
def model_configuration_field_update_function(
base_model_field_index,
model_configuration_field_index
):
base_model_field_value = base_model_array[base_model_field_index]
if base_model_field_value in base_model_object_of_model_configuration_arrays[base_model_field_value][model_configuration_field_index]:
model_configuration_name_value = base_model_object_of_model_configuration_arrays[base_model_field_value][model_configuration_field_index]
stored_model_configuration_names_object[base_model_field_value] = model_configuration_names_object[model_configuration_name_value]
is_default_config_state = 0
if model_configuration_name_value in default_model_configuration_object:
is_default_config_state = 1
negative_prompt_field_visibility = True
negative_prompt_for_sdxl_turbo_field_visibility = False
base_model_num_inference_steps_field_visibility = True
base_model_num_inference_steps_field_for_sdxl_turbo_visibility = False
guidance_scale_field_visibility = True
guidance_scale_for_sdxl_turbo_field_visibility = False
if base_model_field_value == "sdxl_turbo":
negative_prompt_field_visibility = False
negative_prompt_for_sdxl_turbo_field_visibility = True
base_model_num_inference_steps_field_visibility = False
base_model_num_inference_steps_field_for_sdxl_turbo_visibility = True
guidance_scale_field_visibility = False
guidance_scale_for_sdxl_turbo_field_visibility = True
negative_prompt_field_update = gr.Textbox(
visible = negative_prompt_field_visibility
)
negative_prompt_for_sdxl_turbo_field_update = gr.HTML(
visible = negative_prompt_for_sdxl_turbo_field_visibility
)
base_model_num_inference_steps_field_update = gr.Slider(
visible = base_model_num_inference_steps_field_visibility
)
base_model_num_inference_steps_field_for_sdxl_turbo_update = gr.Slider(
visible = base_model_num_inference_steps_field_for_sdxl_turbo_visibility
)
guidance_scale_field_update = gr.Slider(
visible = guidance_scale_field_visibility
)
guidance_scale_for_sdxl_turbo_field_update = gr.HTML(
visible = guidance_scale_for_sdxl_turbo_field_visibility
)
refiner_default_config_accordion_visibility = False
refiner_online_config_accordion_visibility = True
if is_default_config_state == 1:
refiner_default_config_accordion_visibility = True
refiner_online_config_accordion_visibility = False
refining_selection_automatically_selected_message_field_visibility = False
refining_selection_online_config_normal_field_visibility = True
refining_selection_online_config_automatically_selected_field_visibility = False
if model_configuration_name_value in model_configuration_force_refiner_object:
refining_selection_automatically_selected_message_field_visibility = True
refining_selection_online_config_normal_field_visibility = False
refining_selection_online_config_automatically_selected_field_visibility = True
refining_number_of_iterations_for_online_config_field_visibility = False
if model_configuration_name_value in model_configuration_include_refiner_number_of_steps_object:
refining_number_of_iterations_for_online_config_field_visibility = True
refiner_default_config_accordion_update = gr.Accordion(
visible = refiner_default_config_accordion_visibility
)
refiner_online_config_accordion_update = gr.Accordion(
visible = refiner_online_config_accordion_visibility
)
refining_selection_automatically_selected_message_field_update = gr.Markdown(
visible = refining_selection_automatically_selected_message_field_visibility
)
refining_selection_online_config_normal_field_update = gr.Radio(
visible = refining_selection_online_config_normal_field_visibility
)
refining_selection_online_config_automatically_selected_field_update = gr.Radio(
visible = refining_selection_online_config_automatically_selected_field_visibility
)
refining_number_of_iterations_for_online_config_field_update = gr.Radio(
visible = refining_number_of_iterations_for_online_config_field_visibility
)
return {
negative_prompt_field: negative_prompt_field_update,
negative_prompt_for_sdxl_turbo_field: negative_prompt_for_sdxl_turbo_field_update,
base_model_num_inference_steps_field: base_model_num_inference_steps_field_update,
base_model_num_inference_steps_field_for_sdxl_turbo_field: base_model_num_inference_steps_field_for_sdxl_turbo_update,
guidance_scale_field: guidance_scale_field_update,
guidance_scale_for_sdxl_turbo_field: guidance_scale_for_sdxl_turbo_field_update,
refiner_default_config_accordion: refiner_default_config_accordion_update,
refiner_online_config_accordion: refiner_online_config_accordion_update,
refining_selection_automatically_selected_message_field: refining_selection_automatically_selected_message_field_update,
refining_selection_online_config_normal_field: refining_selection_online_config_normal_field_update,
refining_selection_online_config_automatically_selected_field: refining_selection_online_config_automatically_selected_field_update,
refining_number_of_iterations_for_online_config_field: refining_number_of_iterations_for_online_config_field_update
}
error_function("Error")
#####################
#
# Update Refiner and Upscaler Status Function
#
# When the refiner or upscaler is turned on or off, a text message is
# printed on the page. That needs to be updated.
#
#####################
def update_refiner_and_upscaler_status_function(
base_model_field_index,
model_configuration_field_index,
refining_selection_default_config_field_value,
refining_selection_online_config_normal_field_value,
refining_selection_online_config_automatically_selected_field_value,
upscaling_selection_field_value
):
base_model_field_value = base_model_array[base_model_field_index]
if base_model_field_value in base_model_object_of_model_configuration_arrays[base_model_field_value][model_configuration_field_index]:
model_configuration_name_value = base_model_object_of_model_configuration_arrays[base_model_field_value][model_configuration_field_index]
is_default_config_state = 0
if model_configuration_name_value in default_model_configuration_object:
is_default_config_state = 1
refining_selection_default_config_field_value = numerical_bool(refining_selection_default_config_field_value)
refining_selection_online_config_normal_field_value = numerical_bool(refining_selection_online_config_normal_field_value)
refining_selection_online_config_automatically_selected_field_value = numerical_bool(refining_selection_online_config_automatically_selected_field_value)
upscaling_selection_field_value = numerical_bool(upscaling_selection_field_value)
refiner_and_upscaler_status_text = refiner_and_upscaler_status_opening_html
if (
(
(is_default_config_state == 1) and
refining_selection_default_config_field_value
) or (
(is_default_config_state != 1) and
(
(
(model_configuration_name_value not in model_configuration_force_refiner_object) and
refining_selection_online_config_normal_field_value
) or (
(model_configuration_name_value in model_configuration_force_refiner_object) and
refining_selection_online_config_automatically_selected_field_value
)
)
)
):
refiner_and_upscaler_status_text += refiner_on_text
else:
refiner_and_upscaler_status_text += refiner_off_text
if upscaling_selection_field_value == 1:
refiner_and_upscaler_status_text += upscaler_on_text
else:
refiner_and_upscaler_status_text += upscaler_off_text
refiner_and_upscaler_status_text += refiner_and_upscaler_status_closing_html
refiner_and_upscaler_text_field_update = gr.HTML(
value = refiner_and_upscaler_status_text
)
return {
refiner_and_upscaler_text_field: refiner_and_upscaler_text_field_update
}
error_function("Error")
###############################################################################
###############################################################################
#
#
#
#
#
#
# Create Web Display
#
#
#
#
#
#
###############################################################################
###############################################################################
# Hide border when yield is used:
# https://github.com/gradio-app/gradio/issues/5479
# .generating {border: none !important;}
#
# Remove orange border for generation progress.
# #generation_progress_id div {border: none;}
css_to_use = "footer{display:none !important}"
if show_image_creation_progress_log == 1:
css_to_use += "#generation_progress_id div {border: none;}"
with gr.Blocks(
title = "AI Image Creation",
css = css_to_use,
theme = gr.themes.Default(
spacing_size = gr.themes.sizes.spacing_md,
# spacing_size = gr.themes.sizes.spacing_sm,
radius_size = gr.themes.sizes.radius_none
),
analytics_enabled = False
) as sd_interface:
gr.Markdown(opening_html)
with gr.Row():
with gr.Column(scale = 1):
generate_image_btn = gr.Button(
value = "Generate",
variant = "primary"
)
with gr.Group():
with gr.Row():
prompt_field = gr.Textbox(
label = "Prompt (77 token limit):",
value = default_prompt
)
with gr.Row():
negative_prompt_field = gr.Textbox(
label = "Negative Prompt (77 token limit):",
value = default_negative_prompt,
visible = default_negative_prompt_field_visibility
)
with gr.Row():
negative_prompt_for_sdxl_turbo_field = gr.HTML(
value = "<div style=\"padding: 10px; text-align: center; background: #fff;\">Negative prompt is not used for SDXL Turbo.</div>",
visible = default_negative_prompt_for_sdxl_turbo_field_visibility
)
with gr.Group(
visible = refiner_group_visible
):
with gr.Accordion(
label = "Refiner (Default configuration)",
elem_id = "refiner_default_config_accordion_id",
open = refiner_default_config_accordion_open,
visible = refiner_default_config_accordion_visible
) as refiner_default_config_accordion:
#
#
#
# Refiner (Default configuration)
#
#
#
with gr.Row():
gr.Markdown("This can be used if the image has too much noise.")
with gr.Row():
refining_selection_default_config_field = gr.Radio(
choices = ["Yes", "No"],
value = default_refine_option,
show_label = False,
container = False
)
with gr.Row():
refining_denoise_start_for_default_config_field = gr.Slider(
label = "Refiner denoise start %",
minimum = 0.7,
maximum = 0.99,
value = 0.95,
step = 0.01
)
with gr.Row():
refining_use_denoising_start_in_base_model_when_using_refiner_field = gr.Checkbox(
label = "Use \"denoising_start\" value as \"denoising_end\" value in base model generation when using refiner",
value = default_use_denoising_start_in_base_model_when_using_refiner_is_selected,
interactive = True,
container = True
)
with gr.Row():
refining_base_model_output_to_refiner_is_in_latent_space_field = gr.Checkbox(
label = "Base model output in latent space instead of PIL image when using refiner",
value = default_base_model_output_to_refiner_is_in_latent_space_is_selected,
interactive = True,
container = True
)
with gr.Accordion(
label = "Refiner (Online configuration)",
elem_id = "refiner_online_config_accordion_id",
open = refiner_online_config_accordion_open,
visible = refiner_online_config_accordion_visible
) as refiner_online_config_accordion:
#
#
#
# Refiner (Online configuration)
#
#
#
refining_selection_automatically_selected_message_field_visible = False
refining_selection_online_config_normal_field_visible = True
refining_selection_online_config_automatically_selected_field_visible = False
if model_configuration_requires_refiner == 1:
refining_selection_automatically_selected_message_field_visible = True
refining_selection_online_config_normal_field_visible = False
refining_selection_online_config_automatically_selected_field_visible = True
with gr.Row():
refining_selection_automatically_selected_message_field = gr.Markdown(
value = "The online configuration you selected automatically uses the refiner.",
visible = refining_selection_automatically_selected_message_field_visible
)
with gr.Row():
refining_selection_online_config_normal_field = gr.Radio(
choices = ["Yes", "No"],
value = default_refine_option,
show_label = False,
container = False,
visible = refining_selection_online_config_normal_field_visible
)
with gr.Row():
refining_selection_online_config_automatically_selected_field = gr.Radio(
choices = ["Yes"],
value = "Yes",
show_label = False,
container = False,
visible = refining_selection_online_config_automatically_selected_field_visible
)
with gr.Row():
refining_denoise_start_for_online_config_field = gr.Slider(
label = "Refiner denoise start %",
minimum = 0.7,
maximum = 0.99,
value = 0.95,
step = 0.01
)
with gr.Row():
refining_number_of_iterations_for_online_config_field_visible = False
if default_model_configuration in model_configuration_include_refiner_number_of_steps_object:
refining_number_of_iterations_for_online_config_field_visible = True
refining_number_of_iterations_for_online_config_field = gr.Slider(
label = "Refiner number of iterations",
minimum = 1,
maximum = 100,
value = 100,
step = 1,
visible = refining_number_of_iterations_for_online_config_field_visible
)
with gr.Group(
visible = upscaler_group_visible
):
with gr.Accordion(
label = "Upscaler",
elem_id = "upscaler_accordion_id",
open = upscaler_accordion_open,
visible = upscaler_group_visible
):
#
#
#
# Upscaler
#
#
#
with gr.Row():
gr.Markdown("Upscale by 2x?")
with gr.Row():
upscaling_selection_field = gr.Radio(
choices = ['Yes', 'No'],
value = default_upscale_option,
show_label = False,
container = False
)
with gr.Row():
upscaling_num_inference_steps_field = gr.Slider(
label = "Upscaler number of iterations",
minimum = 1,
maximum = 100,
value = 100,
step = 1
)
if (
(enable_refiner == 1) or
(enable_upscaler == 1)
):
refiner_and_upscaler_text_field = gr.HTML(
value = default_refiner_and_upscaler_status_text
)
with gr.Column(scale = 1):
with gr.Group():
with gr.Row():
base_model_field = gr.Dropdown(
label = "Base Model:",
choices = default_base_model_choices_array,
value = default_base_model_nicely_named_value,
type = "index",
#info = "Main model type",
filterable = False,
min_width = 240,
interactive = True
)
model_configuration_field = gr.Dropdown(
label = "Configuration Type:",
choices = default_model_configuration_choices_array,
value = default_model_configuration_nicely_named_value,
type = "index",
#info = "See end of page for info.",
filterable = False,
min_width = 240,
interactive = True
)
with gr.Row():
image_width_field = gr.Slider(
label = "Width:",
minimum = 256,
maximum = 1024,
value = default_width,
step = width_and_height_input_slider_steps,
interactive = True
)
image_height_field = gr.Slider(
label = "Height:",
minimum = 256,
maximum = 1024,
value = default_height,
step = width_and_height_input_slider_steps,
interactive = True
)
with gr.Row():
base_model_num_inference_steps_field = gr.Slider(
label = "Steps:",
minimum = 1,
maximum = 100,
value = default_base_model_base_model_num_inference_steps,
step = 1,
visible = default_base_model_num_inference_steps_field_visibility,
interactive = True
)
with gr.Row():
base_model_num_inference_steps_field_for_sdxl_turbo_field = gr.Slider(
label = "Steps:",
info = "Try using only 1 or a couple of steps.",
minimum = 1,
maximum = 25,
value = default_base_model_base_model_num_inference_steps_for_sdxl_turbo,
step = 1,
visible = default_base_model_num_inference_steps_field_for_sdxl_turbo_field_visibility,
interactive = True
)
with gr.Row():
guidance_scale_field = gr.Slider(
label = "Guidance Scale:",
minimum = 1,
maximum = 15,
value = default_guidance_scale_value,
step = 0.25,
visible = default_guidance_scale_field_visibility,
interactive = True
)
with gr.Row():
guidance_scale_for_sdxl_turbo_field = gr.HTML(
value = "<div style=\"padding: 10px; text-align: center; background: #fff;\">Guidance scale is not used for SDXL Turbo.</div>",
visible = default_guidance_scale_for_sdxl_turbo_field_visibility
)
with gr.Row():
if make_seed_selection_a_textbox == 1:
seed_field = gr.Textbox(
label = "Seed (0 is random; " + str(default_seed_maximum) + " max):",
value = "0",
interactive = True
)
else:
seed_field = gr.Slider(
label = "Seed (0 is random):",
minimum = 0,
maximum = default_seed_maximum,
value = default_seed_value,
step = 1,
interactive = True
)
with gr.Column(scale = 1):
with gr.Row():
if use_image_gallery == 1:
show_download_button = False
if show_download_button_for_gallery == 1:
show_download_button = True
output_image_field = gr.Gallery(
label = "Generated Images",
value = [],
# columns = 1,
# rows = 1,
selected_index = 0,
elem_id = "image_gallery",
allow_preview = "True",
preview = True,
show_download_button = show_download_button
)
else:
output_image_field = gr.Image(
label = "Generated Image",
type = "pil"
)
with gr.Row():
output_text_field = gr.Textbox(
label = "Prompt Information:",
value = "After an image is generated, its generation information will appear here." + additional_prompt_info_html,
show_copy_button = True,
lines = 10,
max_lines = 20,
every = None#,
#container = False
)
with gr.Row():
log_text_field = gr.Textbox(
label = "Generation Progress:",
elem_id = "generation_progress_id",
elem_classes = "",
interactive = False,
value = "",
show_copy_button = False,
visible = False
)
with gr.Row():
prompt_truncated_field = gr.HTML(
value = "",
visible = False
)
if enable_close_command_prompt_button == 1:
cancel_image_btn = gr.Button(
value = "Close Command Prompt / Cancel",
variant = "stop"
)
gr.Markdown("Closing the command prompt will cancel any images in the process of being created. You will need to launch it again to create more images.")
if len(ending_html) > 0:
with gr.Accordion(
label = "Information",
elem_id = "information_section_id",
open = True
):
gr.Markdown(ending_html)
base_model_field.change(
fn = base_model_field_update_function,
inputs = [
base_model_field
],
outputs = [
model_configuration_field,
negative_prompt_field,
negative_prompt_for_sdxl_turbo_field,
base_model_num_inference_steps_field,
base_model_num_inference_steps_field_for_sdxl_turbo_field,
guidance_scale_field,
guidance_scale_for_sdxl_turbo_field
],
queue = None,
show_progress = "hidden"
)
model_configuration_field.change(
fn = model_configuration_field_update_function,
inputs = [
base_model_field,
model_configuration_field
],
outputs = [
negative_prompt_field,
negative_prompt_for_sdxl_turbo_field,
base_model_num_inference_steps_field,
base_model_num_inference_steps_field_for_sdxl_turbo_field,
guidance_scale_field,
guidance_scale_for_sdxl_turbo_field,
refiner_default_config_accordion,
refiner_online_config_accordion,
refining_selection_automatically_selected_message_field,
refining_selection_online_config_normal_field,
refining_selection_online_config_automatically_selected_field,
refining_number_of_iterations_for_online_config_field
],
queue = None,
show_progress = "hidden"
)
if use_image_gallery == 1:
output_image_field.select(
fn = update_prompt_info_from_gallery,
inputs = None,
outputs = [
output_image_field,
output_text_field
],
show_progress = "hidden"
)
if (
(enable_refiner == 1) or
(enable_upscaler == 1)
):
triggers_array = []
if enable_refiner == 1:
triggers_array.extend([
refining_selection_default_config_field.change,
refining_selection_online_config_normal_field.change,
refining_selection_online_config_automatically_selected_field.change,
model_configuration_field.change
])
if enable_upscaler == 1:
triggers_array.extend([
upscaling_selection_field.change
])
gr.on(
triggers = triggers_array,
fn = update_refiner_and_upscaler_status_function,
inputs = [
base_model_field,
model_configuration_field,
refining_selection_default_config_field,
refining_selection_online_config_normal_field,
refining_selection_online_config_automatically_selected_field,
upscaling_selection_field
],
outputs = [
refiner_and_upscaler_text_field
],
queue = None,
show_progress = "hidden"
)
generate_image_btn_click_event = generate_image_btn.click(
fn = before_create_image_function,
inputs = [],
outputs = [
generate_image_btn,
output_image_field,
output_text_field,
log_text_field#,
#prompt_field,
#negative_prompt_field,
#refining_selection_default_config_field,
#refining_denoise_start_for_default_config_field,
#refining_use_denoising_start_in_base_model_when_using_refiner_field,
#refining_base_model_output_to_refiner_is_in_latent_space_field,
#refining_selection_online_config_normal_field,
#refining_selection_online_config_automatically_selected_field,
#refining_denoise_start_for_online_config_field,
#refining_number_of_iterations_for_online_config_field,
#upscaling_selection_field,
#upscaling_num_inference_steps_field,
#base_model_field,
#model_configuration_field,
#image_width_field,
#image_height_field,
#base_model_num_inference_steps_field,
#base_model_num_inference_steps_field_for_sdxl_turbo_field,
#guidance_scale_field,
#seed_field
],
show_progress = "minimal",
queue = True
).then(
fn = create_image_function,
inputs = [
base_model_field,
model_configuration_field,
prompt_field,
negative_prompt_field,
image_width_field,
image_height_field,
guidance_scale_field,
base_model_num_inference_steps_field,
base_model_num_inference_steps_field_for_sdxl_turbo_field,
seed_field,
refining_selection_default_config_field,
refining_selection_online_config_normal_field,
refining_selection_online_config_automatically_selected_field,
refining_denoise_start_for_default_config_field,
refining_use_denoising_start_in_base_model_when_using_refiner_field,
refining_base_model_output_to_refiner_is_in_latent_space_field,
refining_denoise_start_for_online_config_field,
refining_number_of_iterations_for_online_config_field,
upscaling_selection_field,
upscaling_num_inference_steps_field
],
outputs = [
output_image_field,
output_text_field,
prompt_truncated_field
],
queue = True
).then(
fn = after_create_image_function,
inputs = [],
outputs = [
generate_image_btn,
output_text_field,
log_text_field#,
#prompt_field,
#negative_prompt_field,
#refining_selection_default_config_field,
#refining_denoise_start_for_default_config_field,
#refining_use_denoising_start_in_base_model_when_using_refiner_field,
#refining_base_model_output_to_refiner_is_in_latent_space_field,
#refining_selection_online_config_normal_field,
#refining_selection_online_config_automatically_selected_field,
#refining_denoise_start_for_online_config_field,
#refining_number_of_iterations_for_online_config_field,
#upscaling_selection_field,
#upscaling_num_inference_steps_field,
#base_model_field,
#model_configuration_field,
#image_width_field,
#image_height_field,
#base_model_num_inference_steps_field,
#base_model_num_inference_steps_field_for_sdxl_turbo_field,
#guidance_scale_field,
#seed_field
],
queue = False
)
sd_interface_load_kwargs = {
"scroll_to_output": False,
"show_progress": "full"
}
if show_image_creation_progress_log == 1:
sd_interface_continuous = sd_interface.load(
fn = update_log_progress,
inputs = None,
outputs = [
log_text_field
],
every = 1,
**sd_interface_load_kwargs
)
else:
sd_interface_continuous = sd_interface.load(
**sd_interface_load_kwargs
)
if enable_close_command_prompt_button == 1:
# https://github.com/gradio-app/gradio/pull/2433/files
cancel_image_btn.click(
fn = cancel_image_processing,
inputs = None,
outputs = None,
cancels = [generate_image_btn_click_event]
)
sd_interface.queue(
max_size = 20
)
inbrowser = False
if auto_open_browser == 1:
inbrowser = True
sd_interface.launch(
inbrowser = inbrowser,
# debug = True,
share = None,
show_api = False,
quiet = True,
show_error = True,
max_threads = 1
)
|