Spaces:
Running
Running
File size: 168,880 Bytes
af8fa93 f438072 af8fa93 2c66a58 e2098ef 2c66a58 e2098ef 2ac8caf e2098ef 2c66a58 a913558 e2098ef 2c66a58 e2098ef 2c66a58 e2098ef a913558 e2098ef 8c20ff6 22af080 8c20ff6 22af080 a913558 22af080 2c66a58 a913558 8c20ff6 a913558 8c20ff6 a913558 79ebf1d abc742b af8fa93 0f29c3b af8fa93 44efbff af8fa93 aab81af 937a7d5 db0616f 79ebf1d db0616f 79ebf1d 86979b5 79ebf1d 86979b5 db0616f 79ebf1d 937a7d5 79ebf1d 937a7d5 db0616f 41973f9 937a7d5 c41b46e 5e9efe4 c41b46e 937a7d5 db0616f 937a7d5 db0616f 937a7d5 db0616f 937a7d5 d003291 6c7c5ff 937a7d5 79ebf1d 86979b5 79ebf1d 86979b5 79ebf1d 937a7d5 79ebf1d 937a7d5 41973f9 c41b46e 5e9efe4 c41b46e 937a7d5 db0616f 937a7d5 db0616f 937a7d5 2bdeeef d62cdaa 2bdeeef d62cdaa 338aa8b d62cdaa 2bdeeef d62cdaa 338aa8b 2bdeeef d62cdaa 2bdeeef d62cdaa 2bdeeef d62cdaa 2bdeeef d62cdaa 489ab2a 338aa8b 489ab2a 338aa8b 489ab2a 4babf88 c41b46e 5e9efe4 4babf88 489ab2a 338aa8b 489ab2a e95db4e 43a76a1 489ab2a 338aa8b 489ab2a 338aa8b 489ab2a b95ddcd 338aa8b b95ddcd d62cdaa 338aa8b b95ddcd 338aa8b b95ddcd 338aa8b b95ddcd 338aa8b b95ddcd 2cab1ca b95ddcd 338aa8b b95ddcd 7dcb6c1 db31cfe 7dcb6c1 6793c76 db31cfe 7dcb6c1 db31cfe 7dcb6c1 db31cfe 7dcb6c1 db31cfe 7dcb6c1 b4f9679 7dcb6c1 db31cfe 7dcb6c1 489ab2a 338aa8b 489ab2a 338aa8b 489ab2a 338aa8b 489ab2a 338aa8b 489ab2a 338aa8b 4babf88 489ab2a 4babf88 489ab2a c3cb63d 338aa8b c3cb63d 2cab1ca c3cb63d 338aa8b c3cb63d 468c76a a25bc66 468c76a c3cb63d a25bc66 c3cb63d a25bc66 c3cb63d a25bc66 c3cb63d 9e802b7 c3cb63d 360b5be a25bc66 360b5be a25bc66 360b5be 468c76a a25bc66 360b5be a25bc66 360b5be a25bc66 360b5be a25bc66 360b5be b4f9679 360b5be c3cb63d a25bc66 f9fa176 a25bc66 f9fa176 a25bc66 f9fa176 a25bc66 f9fa176 a25bc66 f9fa176 a25bc66 f9fa176 db31cfe f9fa176 db31cfe f9fa176 9535a4e 0c6109e 9535a4e f9fa176 0c6109e f9fa176 0c6109e f9fa176 0c6109e f9fa176 0c6109e f9fa176 0c6109e 0176918 0c6109e 0176918 9535a4e 0c6109e 0176918 0c6109e 0176918 0c6109e 0176918 0c6109e 0176918 0c6109e 0176918 0c6109e c3cb63d 0c6109e c3cb63d 0c6109e c3cb63d 0c6109e c3cb63d 0c6109e c3cb63d 489ab2a 0c6109e 489ab2a 1a5f8f8 489ab2a a25bc66 489ab2a f269530 c4be7c2 345d655 c4be7c2 f269530 345d655 f269530 345d655 f269530 345d655 f269530 345d655 f269530 345d655 935382c 345d655 935382c c4be7c2 345d655 935382c 345d655 935382c 345d655 935382c 345d655 935382c 345d655 935382c 345d655 f269530 345d655 f269530 345d655 f269530 345d655 f269530 345d655 f269530 345d655 f269530 116b5ff f269530 345d655 f269530 ae14754 fb4b7b1 4aadfea fb4b7b1 ae14754 1464bca ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 7453a49 4aadfea 7453a49 fb4b7b1 4aadfea 7453a49 4aadfea 7453a49 4aadfea 7453a49 4aadfea 7453a49 4aadfea 7453a49 4aadfea 7453a49 ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 4aadfea ae14754 134f55d ae14754 4aadfea ae14754 adbef73 c13961f b5c2d8d c13961f adbef73 05756ea adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 87a6296 b5c2d8d 87a6296 c13961f b5c2d8d 87a6296 b5c2d8d 87a6296 b5c2d8d 87a6296 b5c2d8d 87a6296 b5c2d8d 87a6296 b5c2d8d 87a6296 adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 b5c2d8d adbef73 2d9f808 adbef73 b5c2d8d adbef73 81ef9fb 54b9a68 294e2ce 54b9a68 81ef9fb cb7b720 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb d3f4e5f 294e2ce d3f4e5f 294e2ce d3f4e5f 294e2ce d3f4e5f 54b9a68 294e2ce d3f4e5f 294e2ce d3f4e5f 294e2ce d3f4e5f 294e2ce d3f4e5f 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 294e2ce 81ef9fb 2403576 81ef9fb 294e2ce 81ef9fb 1e24d8d f8cd563 5eac1a0 f8cd563 1e24d8d ae8e06a 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d db04211 5eac1a0 db04211 5eac1a0 db04211 5eac1a0 db04211 f8cd563 5eac1a0 db04211 5eac1a0 db04211 5eac1a0 db04211 5eac1a0 db04211 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 5eac1a0 1e24d8d 4c88fdc 1e24d8d 5eac1a0 1e24d8d 2bc9abf e69584b abd9e71 e69584b 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf a459a0d abd9e71 a459a0d e69584b abd9e71 a459a0d abd9e71 a459a0d abd9e71 a459a0d abd9e71 a459a0d abd9e71 a459a0d abd9e71 a459a0d 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf abd9e71 2bc9abf 37fbb4a 2bc9abf abd9e71 2bc9abf af8fa93 3bbe849 af8fa93 937a7d5 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 3bbe849 af8fa93 0f29c3b af8fa93 0f29c3b af8fa93 937a7d5 af8fa93 3bbe849 af8fa93 3bbe849 937a7d5 2cab1ca 937a7d5 3bbe849 937a7d5 d003291 3bbe849 2cab1ca 937a7d5 2cab1ca af8fa93 937a7d5 3bbe849 937a7d5 af8fa93 4f19e2d d62cdaa 4f19e2d af8fa93 a3ef8aa faf44dd a3ef8aa 20ede28 ed6413c 2c66a58 a3ef8aa 20ede28 19eeafd a3ef8aa a4ec709 f438072 a3ef8aa f438072 a913558 f438072 a913558 f438072 e5b2e62 5c6d055 e5b2e62 f14c9eb 10fcc48 e5b2e62 a3ef8aa 3bbe849 937a7d5 ecac45b 338aa8b af8fa93 |
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 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 |
import gradio as gr
import subprocess, shutil, os, zipfile, datetime, sys, time, uuid, stat, re
from pathlib import Path
import base64
# =====================
# Version guard
# =====================
def _ensure_versions():
import importlib, subprocess, sys
def get_version(pkg):
try:
m = importlib.import_module(pkg)
return getattr(m, "__version__", "0")
except Exception:
return "0"
try:
from packaging.version import Version
except ImportError:
# 安装packaging,确保下面版本比较能用
subprocess.check_call([sys.executable, "-m", "pip", "install", "packaging"])
from packaging.version import Version
# 检查 huggingface_hub
hub_ver = get_version("huggingface_hub")
hv = Version(hub_ver)
required_min = Version("0.24.0")
required_max = Version("1.0.0")
hub_ok = required_min <= hv < required_max
if not hub_ok:
print(f"[INFO] huggingface_hub=={hub_ver} not in range "
f"[{required_min}, {required_max}), reinstalling...")
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"huggingface-hub==0.27.1",
"transformers==4.48.0",
"--force-reinstall", "--no-deps"
])
else:
print(f"[INFO] huggingface_hub version OK: {hub_ver}")
_ensure_versions()
# =====================
# Paths (read-only repo root; DO NOT write here)
# =====================
ROOT = Path(__file__).resolve().parent
RUNS_DIR = ROOT / "runs" # all per-run workspaces live here
RUNS_DIR.mkdir(parents=True, exist_ok=True)
TIMEOUT_SECONDS = 1800 # 30 minutes
RETENTION_HOURS = 1 # auto-clean runs older than N hours
DEFAULT_RIGHT_LOGO_PATH = ROOT / "template" / "logos" / "right_logo.png"
# ---------------------
# Utils
# ---------------------
def _now_str():
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def _write_logs(log_path: Path, logs):
try:
log_path.parent.mkdir(parents=True, exist_ok=True)
with open(log_path, "w", encoding="utf-8") as f:
f.write("\n".join(logs))
except Exception:
pass
def _find_ui_header_logos(root: Path):
"""Return list of Paths for UI header logos in order camel → tvg → waterloo.
Prefer template/logos; fallback to assets folders; if none match, return up to 3 images.
"""
preferred = root / "template" / "logos"
# Desired visual order (left → right) with CAMEL at rightmost:
names = ["tvg", "waterloo", "camel"]
found = []
# Try preferred dir first with explicit names
try:
if preferred.exists():
allp = list(preferred.iterdir())
for key in names:
for p in allp:
if p.is_file() and p.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"} and key in p.name.lower():
found.append(p)
break
except Exception:
pass
# If not all found, search broader locations
if len(found) < 3:
cand_dirs = [
root / "assets",
root / "assets" / "logos",
root / "Paper2Poster" / "assets",
root / "Paper2Poster" / "assets" / "logos",
root / "paper2poster" / "assets",
root / "paper2poster" / "assets" / "logos",
]
imgs = []
for d in cand_dirs:
try:
if d.exists():
for p in d.iterdir():
if p.is_file() and p.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"}:
imgs.append(p)
except Exception:
continue
for key in names:
if any(key in str(fp).lower() for fp in found):
continue
for p in imgs:
if key in p.name.lower():
found.append(p)
break
# Fallback: fill up to 3
if not found and imgs:
found = imgs[:3]
return found
def _ui_header_logos_html():
"""Return an HTML div with base64-embedded logos to avoid broken /file routes.
Logos are fixed at top-right, slightly inset, with larger spacing.
"""
import base64
logos = _find_ui_header_logos(ROOT)
if not logos:
return ""
parts = []
for p in logos:
try:
b = p.read_bytes()
b64 = base64.b64encode(b).decode("utf-8")
mime = "image/png" if p.suffix.lower() == ".png" else "image/jpeg"
src = f"data:{mime};base64,{b64}"
name = p.name.lower()
href = None
if "camel" in name:
href = "https://www.camel-ai.org/"
elif "tvg" in name or "torr" in name:
href = "https://torrvision.com/index.html"
elif "waterloo" in name:
href = "https://uwaterloo.ca/"
img = f"<img src='{src}' alt='{p.stem}' style='height:44px;width:auto;object-fit:contain;display:block;cursor:pointer'>"
parts.append(f"<a href='{href}' target='_blank' rel='noopener'>{img}</a>" if href else img)
except Exception:
continue
if not parts:
return ""
# Fixed-position header bar at top-right; moved further left and larger spacing
imgs = "".join(parts)
return (
"<style>"
"#p2p-logo-bar{position:fixed;top:12px;right:140px;display:flex;gap:24px;"
"align-items:center;z-index:9999}"
"#p2p-logo-bar a{display:block;line-height:0}"
"@media (max-width: 768px){#p2p-logo-bar img{height:32px}}"
"</style>"
"<div id='p2p-logo-bar'>" + imgs + "</div>"
)
def _default_conf_logo_path():
"""Pick a default conference logo to preview.
Prefer Paper2Poster/assets/neurips.png, else template/logos/right_logo.png,
else the first of detected header logos.
"""
try:
prefer_assets = ROOT / "Paper2Poster" / "assets" / "neurips.png"
if prefer_assets.exists():
return prefer_assets
pref = ROOT / "template" / "logos" / "right_logo.png"
if pref.exists():
return pref
logos = _find_ui_header_logos(ROOT)
for p in logos:
if p and p.exists():
return p
except Exception:
pass
return None
## Removed sanitizer per request: do not mutate user-generated TeX
def _on_rm_error(func, path, exc_info):
# fix "PermissionError: [Errno 13] Permission denied" for readonly files
os.chmod(path, stat.S_IWRITE)
func(path)
def _copytree(src: Path, dst: Path, symlinks=True, ignore=None):
if dst.exists():
shutil.rmtree(dst, onerror=_on_rm_error)
shutil.copytree(src, dst, symlinks=symlinks, ignore=ignore)
def _safe_copy(src: Path, dst: Path):
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst)
def _cleanup_old_runs(max_age_hours=12):
try:
now = datetime.datetime.now().timestamp()
for run_dir in RUNS_DIR.iterdir():
try:
if not run_dir.is_dir():
continue
mtime = run_dir.stat().st_mtime
age_h = (now - mtime) / 3600.0
if age_h > max_age_hours:
shutil.rmtree(run_dir, onerror=_on_rm_error)
except Exception:
continue
except Exception:
pass
def _prepare_workspace(logs):
"""Create isolated per-run workspace and copy needed code/assets into it."""
run_id = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + "-" + uuid.uuid4().hex[:8]
work_dir = RUNS_DIR / run_id
work_dir.mkdir(parents=True, exist_ok=True)
# Per-run log & zip path
log_path = work_dir / "run.log"
zip_path = work_dir / "output.zip"
logs.append(f"🧩 New workspace: {work_dir.relative_to(ROOT)} (run_id={run_id})")
# Copy code/assets that do file IO so they are run-local (avoid shared writes)
# Keep copies as cheap as possible (symlinks=True when supported)
needed_dirs = ["posterbuilder", "Paper2Poster"]
for d in needed_dirs:
src = ROOT / d
if src.exists():
_copytree(src, work_dir / d, symlinks=True)
logs.append(f" ↪ copied {d}/ → runs/{run_id}/{d}/ (symlink where possible)")
# template/ optional
tmpl = ROOT / "template"
if tmpl.exists():
_copytree(tmpl, work_dir / "template", symlinks=True)
logs.append(" ↪ copied template/")
# pipeline.py must live inside workspace so that ROOT_DIR=work_dir
_safe_copy(ROOT / "pipeline.py", work_dir / "pipeline.py")
# Create standard IO dirs in workspace
(work_dir / "input" / "pdf").mkdir(parents=True, exist_ok=True)
(work_dir / "input" / "logo").mkdir(parents=True, exist_ok=True)
(work_dir / "posterbuilder" / "latex_proj").mkdir(parents=True, exist_ok=True)
return run_id, work_dir, log_path, zip_path
# ---------------------
# Helpers for new features (post-processing)
# ---------------------
def _parse_rgb(val):
"""Return (R, G, B) as ints in [0,255] from '#RRGGBB', 'rgb(...)', 'rgba(...)', 'r,g,b', [r,g,b], or (r,g,b)."""
if val is None:
return None
import re
def clamp255(x):
try:
return max(0, min(255, int(round(float(x)))))
except Exception:
return None
s = str(val).strip()
# list/tuple
if isinstance(val, (list, tuple)) and len(val) >= 3:
r, g, b = [clamp255(val[0]), clamp255(val[1]), clamp255(val[2])]
if None not in (r, g, b):
return (r, g, b)
# hex: #RGB or #RRGGBB
if s.startswith("#"):
hx = s[1:].strip()
if len(hx) == 3:
hx = "".join(c*2 for c in hx)
if len(hx) == 6 and re.fullmatch(r"[0-9A-Fa-f]{6}", hx):
return tuple(int(hx[i:i+2], 16) for i in (0, 2, 4))
# rgb/rgba(...)
m = re.match(r"rgba?\(\s*([^)]+)\)", s, flags=re.IGNORECASE)
if m:
parts = [p.strip() for p in m.group(1).split(",")]
if len(parts) >= 3:
def to_int(p):
if p.endswith("%"):
# percentage to 0-255
return clamp255(float(p[:-1]) * 255.0 / 100.0)
return clamp255(p)
r, g, b = to_int(parts[0]), to_int(parts[1]), to_int(parts[2])
if None not in (r, g, b):
return (r, g, b)
# 'r,g,b'
if "," in s:
parts = [p.strip() for p in s.split(",")]
if len(parts) >= 3:
def to_int(p):
if p.endswith("%"):
return clamp255(float(p[:-1]) * 255.0 / 100.0)
return clamp255(p)
r, g, b = to_int(parts[0]), to_int(parts[1]), to_int(parts[2])
if None not in (r, g, b):
return (r, g, b)
return None
def _apply_meeting_logo(OUTPUT_DIR: Path, meeting_logo_file, logs):
"""Replace output/poster_latex_proj/logos/right_logo.png if meeting_logo_file provided."""
if not meeting_logo_file:
return False
def _ensure_right_logo_default(OUTPUT_DIR: Path, logs):
"""If no right_logo.png exists in output poster project, copy a default NeurIPS logo.
Looks for Paper2Poster/assets/neurips.png first, else template/logos/right_logo.png.
Returns True if a logo was written.
"""
try:
logos_dir = OUTPUT_DIR / "poster_latex_proj" / "logos"
target = logos_dir / "right_logo.png"
if target.exists():
return False
# Preferred default
prefer_assets = ROOT / "Paper2Poster" / "assets" / "neurips.png"
fallback_tpl = ROOT / "template" / "logos" / "right_logo.png"
src = None
if prefer_assets.exists():
src = prefer_assets
elif fallback_tpl.exists():
src = fallback_tpl
if src is None:
logs.append("⚠️ No default right_logo source found (neurips.png or template right_logo.png).")
return False
logos_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, target)
logs.append(f"🏷️ Applied default conference logo → {target.relative_to(OUTPUT_DIR)}")
return True
except Exception as e:
logs.append(f"⚠️ Failed to apply default right_logo: {e}")
return False
logos_dir = OUTPUT_DIR / "poster_latex_proj" / "logos"
target = logos_dir / "right_logo.png"
try:
logos_dir.mkdir(parents=True, exist_ok=True)
# Try to convert to PNG for safety
try:
from PIL import Image
img = Image.open(meeting_logo_file.name)
# preserve alpha if available
if img.mode not in ("RGB", "RGBA"):
img = img.convert("RGBA")
img.save(target, format="PNG")
logs.append(f"🖼️ Meeting logo converted to PNG and saved → {target.relative_to(OUTPUT_DIR)}")
except Exception as e:
# Fallback: raw copy with .png name
shutil.copy(meeting_logo_file.name, target)
logs.append(f"🖼️ Meeting logo copied (no conversion) → {target.relative_to(OUTPUT_DIR)} (note: ensure it's a valid PNG).")
return True
except Exception as e:
logs.append(f"⚠️ Failed to apply meeting logo: {e}")
return False
def _apply_theme_rgb(OUTPUT_DIR: Path, rgb_tuple, logs):
if not rgb_tuple:
return False
tex_path = OUTPUT_DIR / "poster_latex_proj" / "poster_output.tex"
if not tex_path.exists():
logs.append(f"⚠️ Theme RGB skipped: {tex_path.relative_to(OUTPUT_DIR)} not found.")
return False
try:
content = tex_path.read_text(encoding="utf-8")
r, g, b = rgb_tuple
name_pattern = r"(?:nipspurple|neuripspurple|themecolor)"
rgb_pat = rf"(\\definecolor\{{{name_pattern}\}}\{{RGB\}}\{{)\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(\}})"
def repl_rgb(m):
return f"{m.group(1)}{r},{g},{b}{m.group(2)}"
new_content, n = re.subn(rgb_pat, repl_rgb, content, flags=re.MULTILINE)
if n == 0:
hexval = f"{r:02X}{g:02X}{b:02X}"
html_pat = rf"(\\definecolor\{{{name_pattern}\}}\{{HTML\}}\{{)[0-9A-Fa-f]{{6}}(\}})"
def repl_html(m):
return f"{m.group(1)}{hexval}{m.group(2)}"
new_content, n = re.subn(html_pat, repl_html, content, flags=re.MULTILINE)
if n > 0:
tex_path.write_text(new_content, encoding="utf-8")
logs.append(f"🎨 Theme color updated to RGB {{{r},{g},{b}}}")
return True
else:
logs.append("ℹ️ No \\definecolor target found.")
return False
except Exception as e:
logs.append(f"⚠️ Failed to update theme RGB: {e}")
return False
def _apply_left_logo(OUTPUT_DIR: Path, logo_files, logs):
"""
Use the first institutional logo uploaded by the user:
- Copy it into output/poster_latex_proj/logos/ as left_logo.<ext>
- Replace 'logos/left_logo.png' in poster_output.tex with the proper file extension
Does NOT convert formats. Simply renames and rewrites the tex reference.
"""
if not logo_files:
logs.append("ℹ️ No institutional logo uploaded.")
return False
if isinstance(logo_files, (list, tuple)) and len(logo_files) > 1:
logs.append("Multiple institutional logos uploaded.")
return False
# Single file case
f = logo_files[0] if isinstance(logo_files, (list, tuple)) else logo_files
if not f:
logs.append("ℹ️ No institutional logo uploaded.")
return False
ext = Path(f.name).suffix or ".png" # fallback to .png if no extension
logos_dir = OUTPUT_DIR / "poster_latex_proj" / "logos"
tex_path = OUTPUT_DIR / "poster_latex_proj" / "poster_output.tex"
try:
logos_dir.mkdir(parents=True, exist_ok=True)
dst = logos_dir / f"left_logo{ext}"
shutil.copy(f.name, dst)
logs.append(f"🏷️ Institutional logo copied to: {dst.relative_to(OUTPUT_DIR)}")
except Exception as e:
logs.append(f"⚠️ Failed to copy institutional logo: {e}")
return False
if not tex_path.exists():
logs.append("⚠️ poster_output.tex not found, cannot replace left_logo path.")
return False
try:
text = tex_path.read_text(encoding="utf-8")
old = "logos/left_logo.png"
new = f"logos/left_logo{ext}"
if old in text:
tex_path.write_text(text.replace(old, new), encoding="utf-8")
logs.append(f"🛠️ Replaced left_logo.png → left_logo{ext} in poster_output.tex")
return True
# Fallback (covers weird spacing or macro variations)
import re
pattern = r"(logos/left_logo)\.png"
new_text, n = re.subn(pattern, r"\1" + ext, text)
if n > 0:
tex_path.write_text(new_text, encoding="utf-8")
logs.append(f"🛠️ Replaced left_logo.png → left_logo{ext} (regex fallback)")
return True
logs.append("ℹ️ No left_logo.png reference found in poster_output.tex.")
return False
except Exception as e:
logs.append(f"⚠️ Failed to modify poster_output.tex: {e}")
return False
def render_overleaf_button(overleaf_b64):
if not overleaf_b64:
return ""
html = f"""
<form action="https://www.overleaf.com/docs" method="post" target="_blank">
<input type="hidden" name="snip_uri" value="data:application/zip;base64,{overleaf_b64}">
<input type="hidden" name="engine" value="xelatex">
<button style="
background:#4CAF50;color:white;padding:8px 14px;
border:none;border-radius:6px;cursor:pointer; margin-top:8px;
">
🚀 Open in Overleaf
</button>
</form>
"""
return html
def _get_tectonic_bin(logs):
"""Return a usable path to the tectonic binary. Try PATH/common paths; if not found, download to runs/_bin."""
import shutil as _sh, tarfile, urllib.request, os
# 1) existing in PATH or common dirs
cands = [
"tectonic",
str(Path("/usr/local/bin/tectonic")),
str(Path("/usr/bin/tectonic")),
os.path.expanduser("~/.local/bin/tectonic"),
str((RUNS_DIR / "_bin" / "tectonic").resolve()),
]
for c in cands:
if _sh.which(c) or Path(c).exists():
return c
# 2) download to runs/_bin
try:
url = "https://github.com/tectonic-typesetting/tectonic/releases/download/tectonic%400.15.0/tectonic-0.15.0-x86_64-unknown-linux-gnu.tar.gz"
bin_dir = RUNS_DIR / "_bin"
bin_dir.mkdir(parents=True, exist_ok=True)
tgz = bin_dir / "tectonic.tar.gz"
logs.append("⬇️ Downloading tectonic binary …")
with urllib.request.urlopen(url, timeout=60) as resp, open(tgz, "wb") as out:
out.write(resp.read())
with tarfile.open(tgz, "r:gz") as tf:
tf.extractall(path=bin_dir)
# find binary
tbin = None
for p in bin_dir.rglob("tectonic"):
if p.is_file() and os.access(p, os.X_OK):
tbin = p
break
if not tbin:
# make executable if needed
for p in bin_dir.rglob("tectonic"):
try:
p.chmod(0o755)
tbin = p
break
except Exception:
continue
if tbin:
logs.append(f"✅ Tectonic ready at {tbin}")
return str(tbin)
logs.append("⚠️ Tectonic binary not found after download.")
except Exception as e:
logs.append(f"⚠️ Tectonic download failed: {e}")
return None
def _compile_poster_pdf(OUTPUT_DIR: Path, logs):
"""
Compile output/poster_latex_proj/poster_output.tex into a PDF using an
available TeX engine. Prefer 'tectonic', then 'lualatex', then 'xelatex',
then 'latexmk'. Returns Path to the PDF or None.
"""
try:
proj_dir = OUTPUT_DIR / "poster_latex_proj"
tex_path = proj_dir / "poster_output.tex"
if not tex_path.exists():
logs.append(f"⚠️ LaTeX source not found: {tex_path.relative_to(OUTPUT_DIR)}")
return None
# Clean old PDFs
for cand in (proj_dir / "poster_output.pdf", proj_dir / "poster.pdf"):
try:
if cand.exists():
cand.unlink()
except Exception:
pass
import shutil as _sh
import subprocess as _sp
def _has(bin_name):
return _sh.which(bin_name) is not None
# Most-tolerant: prefer latexmk with XeLaTeX and force (-f), then XeLaTeX, then LuaLaTeX
pretex = r"\nonstopmode\scrollmode\makeatletter\let\pgf@error\pgf@warning\let\GenericError\GenericWarning\let\PackageError\PackageWarning\makeatother"
if _has("latexmk"):
cmd = [
"latexmk", "-pdf", "-pdflatex=xelatex", "-f",
"-interaction=nonstopmode", "-file-line-error",
f"-pretex={pretex}",
tex_path.name,
]
logs.append("▶ Compiling with latexmk (-pdf -pdflatex=xelatex -f, pretex demote errors) …")
elif _has("xelatex"):
# Inject pretex macros via direct input to engine (no file mutation)
injected = pretex + f"\\input{{{tex_path.name}}}"
cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", injected]
logs.append("▶ Compiling with xelatex (pretex injected) …")
elif _has("lualatex"):
injected = pretex + f"\\input{{{tex_path.name}}}"
cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", injected]
logs.append("▶ Compiling with lualatex (pretex injected) …")
else:
logs.append("⚠️ No TeX engine found (latexmk/xelatex/lualatex). Skipping PDF compile.")
return None
import os as _os
_env = _os.environ.copy()
# Ensure TeX can find local theme/fonts across project tree
texinputs = _env.get("TEXINPUTS", "")
search = _os.pathsep.join([
str(proj_dir), str(proj_dir) + "//",
str(proj_dir.parent), str(proj_dir.parent) + "//",
])
_env["TEXINPUTS"] = search + _os.pathsep + texinputs
proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
if proc.stdout:
logs.append(proc.stdout[-4000:])
# Accept PDF even if return code is non-zero (be tolerant)
for out_name in ("poster_output.pdf", "poster.pdf", tex_path.stem + ".pdf"):
out_path = proj_dir / out_name
if out_path.exists():
if proc.returncode != 0:
logs.append(f"⚠️ Compile returned code {proc.returncode}, but PDF exists; using it.")
else:
logs.append(f"✅ PDF generated → {out_path.relative_to(OUTPUT_DIR)}")
return out_path
if proc.returncode != 0:
logs.append(f"❌ PDF compile failed with code {proc.returncode} and no PDF produced.")
return None
logs.append("⚠️ PDF not found after compile.")
return None
except Exception as e:
logs.append(f"⚠️ PDF compile error: {e}")
return None
def _pdf_to_iframe_html(pdf_path: Path, width="100%", height="900px") -> str:
try:
b = pdf_path.read_bytes()
b64 = base64.b64encode(b).decode("utf-8")
return (
f"<div style='border:1px solid #ddd;border-radius:8px;overflow:hidden'>"
f"<embed type='application/pdf' width='{width}' height='{height}' src='data:application/pdf;base64,{b64}'></embed>"
f"</div>"
)
except Exception:
return ""
def _pdf_to_iframe_file(pdf_path: Path, width="100%", height="900px") -> str:
try:
from urllib.parse import quote
p = str(pdf_path)
src = f"/file={quote(p)}"
return (
f"<div style='border:1px solid #ddd;border-radius:8px;overflow:hidden'>"
f"<iframe src='{src}' width='{width}' height='{height}' style='border:0'></iframe>"
f"</div>"
)
except Exception:
return ""
def _pdf_to_image_first_page(pdf_path: Path, out_dir: Path, logs) -> Path | None:
try:
out_dir.mkdir(parents=True, exist_ok=True)
out_path = out_dir / "poster_preview.png"
# Try PyMuPDF
try:
import fitz # PyMuPDF
doc = fitz.open(str(pdf_path))
if doc.page_count == 0:
return None
page = doc.load_page(0)
mat = fitz.Matrix(2, 2)
pix = page.get_pixmap(matrix=mat, alpha=False)
pix.save(str(out_path))
return out_path if out_path.exists() else None
except Exception as e:
logs.append(f"⚠️ PyMuPDF render failed: {e}")
# Fallback: pypdfium2
try:
import pypdfium2 as pdfium
pdf = pdfium.PdfDocument(str(pdf_path))
if len(pdf) == 0:
return None
page = pdf[0]
bitmap = page.render(scale=2).to_pil()
bitmap.save(out_path)
return out_path if out_path.exists() else None
except Exception as e:
logs.append(f"⚠️ pypdfium2 render failed: {e}")
except Exception as e:
logs.append(f"⚠️ image preview failed: {e}")
return None
def preview_image_from_pdf(pdf_file):
try:
path = pdf_file
if hasattr(pdf_file, 'name'):
path = pdf_file.name
if not path:
return None
p = Path(path)
logs = []
img = _pdf_to_image_first_page(p, p.parent, logs)
return str(img) if img and img.exists() else None
except Exception:
return None
def _compile_tex_to_pdf(tex_path: Path, logs):
"""Generic TeX compile helper for a .tex file. Returns Path to PDF or None."""
try:
proj_dir = tex_path.parent
import shutil as _sh, subprocess as _sp
def _has(bin_name):
return _sh.which(bin_name) is not None
# Most-tolerant: latexmk first with pretex demoting errors; fallbacks inject pretex, too
pretex = r"\nonstopmode\scrollmode\makeatletter\let\pgf@error\pgf@warning\let\GenericError\GenericWarning\let\PackageError\PackageWarning\makeatother"
if _has("latexmk"):
cmd = [
"latexmk", "-pdf", "-pdflatex=xelatex", "-f",
"-interaction=nonstopmode", "-file-line-error",
f"-pretex={pretex}",
tex_path.name,
]
logs.append("▶ Compiling with latexmk (-pdf -pdflatex=xelatex -f, pretex demote errors) …")
elif _has("xelatex"):
injected = pretex + f"\\input{{{tex_path.name}}}"
cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", injected]
logs.append("▶ Compiling with xelatex (pretex injected) …")
elif _has("lualatex"):
injected = pretex + f"\\input{{{tex_path.name}}}"
cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", injected]
logs.append("▶ Compiling with lualatex (pretex injected) …")
else:
logs.append("⚠️ No TeX engine found (xelatex/lualatex/latexmk).")
return None
import os as _os
_env = _os.environ.copy()
texinputs = _env.get("TEXINPUTS", "")
search = _os.pathsep.join([
str(proj_dir), str(proj_dir) + "//",
str(proj_dir.parent), str(proj_dir.parent) + "//",
])
_env["TEXINPUTS"] = search + _os.pathsep + texinputs
proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
if proc.stdout:
logs.append(proc.stdout[-4000:])
guess = proj_dir / (tex_path.stem + ".pdf")
if proc.returncode != 0:
# Be tolerant: if a PDF was produced despite errors, use it.
if guess.exists():
logs.append(f"⚠️ Compile returned code {proc.returncode}, but PDF exists; using it.")
return guess
logs.append(f"❌ PDF compile failed with code {proc.returncode} and no PDF produced.")
return None
return guess if guess.exists() else None
except Exception as e:
logs.append(f"⚠️ PDF compile error: {e}")
return None
def _ensure_left_logo_or_disable(OUTPUT_DIR: Path, logs):
"""If no left_logo.* exists in logos/, comment out \logoleft line in poster_output.tex."""
tex_path = OUTPUT_DIR / "poster_latex_proj" / "poster_output.tex"
logos_dir = OUTPUT_DIR / "poster_latex_proj" / "logos"
try:
if not tex_path.exists():
return False
# any left_logo.* present?
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if has_left:
return False
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
new_txt = re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\\logoleft in poster_output.tex.")
return True
except Exception as e:
logs.append(f"⚠️ Failed left_logo fallback: {e}")
return False
def debug_compile():
# Disabled minimal LaTeX debug; use the two pipeline-zip tests instead.
return "<div style='color:#555'>Minimal debug disabled. Use 'Test repo output.zip' or 'Test last pipeline zip'.</div>"
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and return preview HTML + PDF path."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>"
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Ensure local fonts present in project and override theme to use them
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_proj/fonts/")
# Copy repository theme .sty files into project root so they take precedence
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
logs.append("📄 Copied template/*.sty → zip_proj/")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
# Copy repository theme .sty files into both root and the .tex dir so they take precedence
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_proj/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
# Append overrides into theme file(s)
for sty in work_zip_dir.rglob("beamerthemegemini.sty"):
with open(sty, "a", encoding="utf-8") as fh:
fh.write("\n% === overrides inserted for local fonts ===\n")
fh.write("\\makeatletter\\@ifpackageloaded{fontspec}{%\n")
fh.write("\\IfFileExists{fonts/Raleway/Raleway-Regular.ttf}{\\renewfontfamily\\Raleway[Path=fonts/Raleway/, UprightFont=*-Regular, ItalicFont=*-Italic, BoldFont=*-Bold, BoldItalicFont=*-BoldItalic, Ligatures=TeX]{Raleway}}{}\n")
fh.write("\\IfFileExists{fonts/Lato/Lato-Regular.ttf}{\\renewfontfamily\\Lato[Path=fonts/Lato/, UprightFont=*-Light, ItalicFont=*-LightItalic, BoldFont=*-Regular, BoldItalicFont=*-Italic, Ligatures=TeX]{Lato}\\setsansfont{Lato}[Path=fonts/Lato/, UprightFont=*-Light, ItalicFont=*-LightItalic, BoldFont=*-Regular, BoldItalicFont=*-Italic]}{}\n")
fh.write("}{ }\\makeatother\n")
logs.append(f"🛠️ Appended local font overrides in {sty.relative_to(work_zip_dir)}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
# Use served file path to avoid data: URI issues
html = _pdf_preview_html(pdf_path, height="700px")
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>", None
# Disable logoleft if missing; also ensure local fonts and override theme to use them
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
# Copy repo-local fonts into the zip project under ./fonts/, then append overrides into theme
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_upload/fonts/")
for sty in work_zip_dir.rglob("beamerthemegemini.sty"):
with open(sty, "a", encoding="utf-8") as fh:
fh.write("\n% === overrides inserted for local fonts ===\n")
fh.write("\\makeatletter\\@ifpackageloaded{fontspec}{%\n")
fh.write("\\IfFileExists{fonts/Raleway/Raleway-Regular.ttf}{\\renewfontfamily\\Raleway[Path=fonts/Raleway/, UprightFont=*-Regular, ItalicFont=*-Italic, BoldFont=*-Bold, BoldItalicFont=*-BoldItalic, Ligatures=TeX]{Raleway}}{}\n")
fh.write("\\IfFileExists{fonts/Lato/Lato-Regular.ttf}{\\renewfontfamily\\Lato[Path=fonts/Lato/, UprightFont=*-Light, ItalicFont=*-LightItalic, BoldFont=*-Regular, BoldItalicFont=*-Italic, Ligatures=TeX]{Lato}\\setsansfont{Lato}[Path=fonts/Lato/, UprightFont=*-Light, ItalicFont=*-LightItalic, BoldFont=*-Regular, BoldItalicFont=*-Italic]}{}\n")
fh.write("}{ }\\makeatother\n")
logs.append(f"🛠️ Appended local font overrides in {sty.relative_to(work_zip_dir)}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>"
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>"
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>"
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_output_zip():
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
# Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>",
None,
)
logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
try:
shutil.copy2(zip_path, ZIP_PATH)
logs.append(f"📦 Staged repo output.zip → runs/{WORK_DIR.name}/output.zip")
_write_logs(LOG_PATH, logs)
except Exception as e:
logs.append(f"❌ Failed staging output.zip: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Failed to stage output.zip</div>"
return debug_compile_last_pipeline_zip()
logs = [f"🐞 Debug(real) at {_now_str()}"]
zip_path = ROOT / "output.zip"
if not zip_path.exists():
return (
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
+ f"<div>Expected at: {zip_path}</div>"
)
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_proj"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append("Unzipping output.zip → zip_proj/")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(zip_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate poster_output.tex (fallback to poster.tex)
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
# fallback: any .tex
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in output.zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
# If left_logo missing, disable \logoleft
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in zip project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def _find_last_pipeline_zip():
try:
candidates = []
for d in RUNS_DIR.iterdir():
try:
if d.is_dir():
z = d / "output.zip"
if z.exists():
candidates.append((z.stat().st_mtime, z))
except Exception:
pass
if not candidates:
return None
candidates.sort(key=lambda x: x[0], reverse=True)
return candidates[0][1]
except Exception:
return None
def debug_compile_last_pipeline_zip():
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
last_zip = _find_last_pipeline_zip()
if not last_zip:
repo_zip = ROOT / "output.zip"
if repo_zip.exists():
try:
_, W, L, Z = _prepare_workspace(logs)
shutil.copy2(repo_zip, Z)
logs.append(f"📦 Auto-staged repo output.zip → runs/{W.name}/output.zip")
last_zip = Z
except Exception as e:
logs.append(f"❌ Auto-stage failed: {e}")
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
else:
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_last"
work_zip_dir.mkdir(parents=True, exist_ok=True)
logs.append(f"Workspace: runs/{WORK_DIR.name}")
logs.append(f"Using: {last_zip}")
# Extract zip
try:
import zipfile as _zf
with _zf.ZipFile(last_zip, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Locate tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in last pipeline zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
# Ensure local fonts and theme precedence (same as other debug path)
try:
src_fonts = ROOT / "template" / "fonts"
dst_fonts = work_zip_dir / "fonts"
if src_fonts.exists():
for root_dir, dirs, files in os.walk(src_fonts):
rel = Path(root_dir).relative_to(src_fonts)
out_dir = dst_fonts / rel
out_dir.mkdir(parents=True, exist_ok=True)
for fn in files:
if fn.lower().endswith((".ttf", ".otf")):
shutil.copy2(Path(root_dir)/fn, out_dir/fn)
logs.append("📁 Copied local fonts → zip_last/fonts/")
# Copy repository theme .sty next to tex and at root
try:
tmpl_dir = ROOT / "template"
for sty in tmpl_dir.glob("*.sty"):
shutil.copy2(sty, work_zip_dir / sty.name)
shutil.copy2(sty, tex_path.parent / sty.name)
logs.append("📄 Copied template/*.sty → zip_last/ and tex dir")
except Exception as e:
logs.append(f"⚠️ Copy sty failed: {e}")
except Exception as e:
logs.append(f"⚠️ Local font setup failed: {e}")
# Compile to PDF
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile last pipeline zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return html, str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
def debug_compile_uploaded_zip(zip_file):
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
logs = [f"🐞 Debug(upload) at {_now_str()}"]
if not zip_file:
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
# Prepare workspace
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
work_zip_dir = WORK_DIR / "zip_upload"
work_zip_dir.mkdir(parents=True, exist_ok=True)
# Save uploaded zip
up_path = work_zip_dir / "input.zip"
try:
shutil.copy(zip_file.name, up_path)
except Exception as e:
logs.append(f"❌ save upload failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Save upload failed.</div>", None
# Extract
try:
import zipfile as _zf
with _zf.ZipFile(up_path, 'r') as zf:
zf.extractall(work_zip_dir)
except Exception as e:
logs.append(f"❌ unzip failed: {e}")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>Unzip failed.</div>", None
# Find tex
tex_path = None
for name in ("poster_output.tex", "poster.tex"):
cand = list(work_zip_dir.rglob(name))
if cand:
tex_path = cand[0]
break
if tex_path is None:
cand = list(work_zip_dir.rglob("*.tex"))
if cand:
tex_path = cand[0]
if tex_path is None:
logs.append("❌ No .tex file found in uploaded zip")
_write_logs(LOG_PATH, logs)
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
# Disable logoleft if missing
try:
logos_dir = tex_path.parent / "logos"
has_left = False
if logos_dir.exists():
for p in logos_dir.iterdir():
if p.is_file() and p.stem == "left_logo":
has_left = True
break
if not has_left:
txt = tex_path.read_text(encoding="utf-8")
if "\\logoleft" in txt:
import re as _re
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
if new_txt != txt:
tex_path.write_text(new_txt, encoding="utf-8")
logs.append("ℹ️ No left_logo found; disabled \\logoleft in uploaded project.")
except Exception as e:
logs.append(f"⚠️ left_logo adjust failed: {e}")
# Compile
pdf_path = _compile_tex_to_pdf(tex_path, logs)
if not pdf_path or not pdf_path.exists():
logs.append("❌ Failed to compile uploaded zip PDF.")
_write_logs(LOG_PATH, logs)
return (
"<div style='color:#b00'><b>Compile failed.</b></div>"
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
+ "\n".join(logs)
+ "</pre>",
None,
)
try:
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
html = (
f"<div style='margin-bottom:8px'>{open_tab}</div>"
+ _pdf_to_iframe_html(pdf_path, height="700px")
)
_write_logs(LOG_PATH, logs)
return "", str(pdf_path)
except Exception as e:
logs.append(f"⚠️ preview failed: {e}")
_write_logs(LOG_PATH, logs)
return f"<div>Compiled but preview failed: {e}</div>", None
# =====================
# Gradio pipeline function (ISOLATED)
# =====================
def run_pipeline(arxiv_url, pdf_file, openai_key, logo_files, meeting_logo_file, theme_rgb):
_cleanup_old_runs(RETENTION_HOURS)
start_time = datetime.datetime.now()
logs = [f"🚀 Starting pipeline at {_now_str()}"]
# --- Prepare per-run workspace ---
run_id, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
INPUT_DIR = WORK_DIR / "input"
OUTPUT_DIR = WORK_DIR / "output"
LOGO_DIR = INPUT_DIR / "logo"
POSTER_LATEX_DIR = WORK_DIR / "posterbuilder" / "latex_proj"
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
# ====== Validation: must upload LOGO ======
if logo_files is None:
logo_files = []
if not isinstance(logo_files, (list, tuple)):
logo_files = [logo_files]
logo_files = [f for f in logo_files if f]
# if len(logo_files) == 0:
# msg = "❌ You must upload at least one institutional logo (multiple allowed)."
# logs.append(msg)
# _write_logs(LOG_PATH, logs)
# yield "\n".join(logs), "", None, ""
# return
# Save logos into run-local dir
for item in LOGO_DIR.iterdir():
if item.is_file():
item.unlink()
saved_logo_paths = []
for lf in logo_files:
p = LOGO_DIR / Path(lf.name).name
shutil.copy(lf.name, p)
saved_logo_paths.append(p)
logs.append(f"🏷️ Saved {len(saved_logo_paths)} logo file(s) → {LOGO_DIR.relative_to(WORK_DIR)}")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
# ====== Handle uploaded PDF (optional) ======
pdf_path = None
if pdf_file:
pdf_dir = INPUT_DIR / "pdf"
pdf_dir.mkdir(parents=True, exist_ok=True)
pdf_path = pdf_dir / Path(pdf_file.name).name
shutil.copy(pdf_file.name, pdf_path)
logs.append(f"📄 Uploaded PDF → {pdf_path.relative_to(WORK_DIR)}")
# For pipeline Step 1.5 compatibility: also copy to input/paper.pdf
canonical_pdf = INPUT_DIR / "paper.pdf"
shutil.copy(pdf_file.name, canonical_pdf)
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
# ====== Validate input source ======
if not arxiv_url and not pdf_file:
msg = "❌ Please provide either an arXiv link or upload a PDF file (choose one)."
logs.append(msg)
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
# ====== Build command (run INSIDE workspace) ======
cmd = [
sys.executable, "pipeline.py",
"--model_name_t", "gpt-5",
"--model_name_v", "gpt-5",
"--result_dir", "output",
"--paper_latex_root", "input/latex_proj",
"--openai_key", openai_key,
"--gemini_key", "##",
"--logo_dir", str(LOGO_DIR) # run-local logo dir
]
if arxiv_url:
cmd += ["--arxiv_url", arxiv_url]
# (Keep pdf via input/paper.pdf; pipeline will read it if exists)
logs.append("\n======= REAL-TIME LOG =======")
logs.append(f"cwd = runs/{WORK_DIR.name}")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
# ====== Run with REAL-TIME streaming, inside workspace ======
try:
process = subprocess.Popen(
cmd,
cwd=str(WORK_DIR),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True,
)
except Exception as e:
msg = f"❌ Pipeline failed to start: {e}"
logs.append(msg)
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
last_yield = time.time()
try:
while True:
# Timeout guard
if (datetime.datetime.now() - start_time).total_seconds() > TIMEOUT_SECONDS:
logs.append("❌ Pipeline timed out (30 min limit). Killing process…")
try:
process.kill()
except Exception:
pass
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
line = process.stdout.readline()
if line:
print(line, end="") # echo to Space logs
logs.append(line.rstrip("\n"))
_write_logs(LOG_PATH, logs)
now = time.time()
if now - last_yield >= 0.3:
last_yield = now
yield "\n".join(logs), "", None, None, ""
elif process.poll() is not None:
break
else:
time.sleep(0.05)
return_code = process.wait()
logs.append(f"\nProcess finished with code {return_code}")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
if return_code != 0:
logs.append("❌ Process exited with non-zero status. See logs above.")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
except Exception as e:
logs.append(f"❌ Error during streaming: {e}")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
finally:
try:
if process.stdout:
process.stdout.close()
except Exception:
pass
# ====== Check output ======
has_output = False
try:
if OUTPUT_DIR.exists():
for _ in OUTPUT_DIR.iterdir():
has_output = True
break
except FileNotFoundError:
has_output = False
if not has_output:
msg = "❌ No output generated. Please check logs above."
logs.append(msg)
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
return
# ====== NEW: Post-processing (optional features) ======
# 1) Optional meeting logo replacement; if not provided, apply default NeurIPS
applied_logo = _apply_meeting_logo(OUTPUT_DIR, meeting_logo_file, logs)
if not applied_logo:
_ensure_right_logo_default(OUTPUT_DIR, logs)
# 2) Optional theme color update
rgb_tuple = _parse_rgb(theme_rgb)
if theme_rgb and not rgb_tuple:
logs.append(f"⚠️ Ignored Theme RGB input '{theme_rgb}': expected like '94,46,145'.")
applied_rgb = _apply_theme_rgb(OUTPUT_DIR, rgb_tuple, logs) if rgb_tuple else False
# 3) Optional institutional logo -> left_logo.<ext>
_apply_left_logo(OUTPUT_DIR, logo_files, logs)
_ensure_left_logo_or_disable(OUTPUT_DIR, logs)
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), "", None, None, ""
# ====== Compile PDF (for download + image preview) ======
pdf_html = ""
compiled_pdf_file = None
try:
pdf_path = _compile_poster_pdf(OUTPUT_DIR, logs)
if pdf_path and pdf_path.exists():
# Prefer file-served iframe to avoid large data: URIs and browser blocks
pdf_html = _pdf_to_iframe_file(pdf_path)
compiled_pdf_file = str(pdf_path)
logs.append("🖨️ PDF compiled (image preview available).")
except Exception as e:
logs.append(f"⚠️ PDF compile skipped: {e}")
# ====== Zip output (run-local) ======
try:
target_dir = OUTPUT_DIR / "poster_latex_proj"
if not target_dir.exists():
logs.append("❌ poster_latex_proj folder not found")
else:
with zipfile.ZipFile(ZIP_PATH, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(target_dir):
for file in files:
file_path = Path(root) / file
arcname = file_path.relative_to(target_dir) # only relative to subfolder
zipf.write(file_path, arcname=arcname)
logs.append(f"✅ Zipped poster_latex_proj → {ZIP_PATH.relative_to(WORK_DIR)}")
except Exception as e:
logs.append(f"❌ Failed to create zip: {e}")
# ====== Prepare Overleaf base64 payload (optional) ======
overleaf_zip_b64 = ""
try:
with open(ZIP_PATH, "rb") as f:
overleaf_zip_b64 = base64.b64encode(f.read()).decode("utf-8")
logs.append("🔗 Prepared Overleaf base64 payload")
except Exception as e:
logs.append(f"⚠️ Failed Overleaf payload: {e}")
end_time = datetime.datetime.now()
dur = (end_time - start_time).seconds
logs.append(f"🏁 Completed at {_now_str()} (Duration: {dur}s)")
logs.append(f"🆔 run_id = {WORK_DIR.name}")
_write_logs(LOG_PATH, logs)
yield "\n".join(logs), (
pdf_html
), (
compiled_pdf_file
), (
str(ZIP_PATH) if ZIP_PATH.exists() else None
), render_overleaf_button(overleaf_zip_b64)
def debug_compile():
# Minimal debug disabled to simplify UI.
return "<div style='color:#555'>Minimal debug disabled. Use 'Test repo output.zip' or 'Test last pipeline zip'.</div>"
# =====================
# Gradio UI
# =====================
with gr.Blocks(title="🎓 Paper2Poster") as iface:
# Title
gr.Markdown("# 🎓 Paper2Poster")
gr.Markdown("""
[Paper](https://arxiv.org/abs/2505.21497) | [GitHub](https://github.com/Paper2Poster/Paper2Poster) | [Project Page](https://paper2poster.github.io/)
**TL;DR:** Upload your paper and get an auto-generated poster.
Please be patient — each paper takes about 8–10 minutes to process.
This work, developed in collaboration with [TVG@Oxford](https://torrvision.com/index.html) and [UWaterloo](https://uwaterloo.ca/), has been accepted to [NeurIPS 2025 D&B](https://neurips.cc/). The framework builds upon 🐪 [CAMEL-ai](https://github.com/camel-ai/camel).
""", elem_id="intro-md")
# Top-right logos (camel, tvg, waterloo) if available
gr.HTML(_ui_header_logos_html())
# Note: CAMEL line merged into the Markdown above to keep it on the same line.
# -------- Input box --------
with gr.Row():
# ========== LEFT: INPUT ==========
with gr.Column(scale=1):
with gr.Accordion("Input", open=True):
arxiv_in = gr.Textbox(label="📘 ArXiv URL (choose one)", placeholder="https://arxiv.org/abs/2505.xxxxx")
pdf_in = gr.File(label="📄 Upload PDF (choose one)")
key_in = gr.Textbox(label="🔑 OpenAI API Key", placeholder="sk-...", type="password")
inst_logo_in = gr.File(
label="🏷️ Institutional Logo (optional, multiple allowed)",
file_count="multiple",
file_types=["image"],
)
with gr.Row():
with gr.Column():
conf_logo_in = gr.File(
label="🧩 Optional: Conference Logo (defaults to NeurIPS logo)",
file_count="single",
file_types=["image"],
)
with gr.Column():
_conf_path = _default_conf_logo_path()
conf_preview = gr.Image(
value=str(_conf_path) if _conf_path else None,
label="Default conference logo preview",
interactive=False,
)
theme_in = gr.ColorPicker(label="🎨 Theme Color (optional)", value="#5E2E91")
run_btn = gr.Button("🚀 Run", variant="primary")
# ========== RIGHT: OUTPUT ==========
with gr.Column(scale=1):
with gr.Accordion("Output", open=True):
# Preview on top
img_out = gr.Image(label="🖼️ Poster (Image Preview)", interactive=False)
# Logs in the middle (keep compact height)
logs_out = gr.Textbox(label="🧾 Logs", lines=10, max_lines=20)
# Downloads at bottom
pdf_out = gr.HTML(label="📄 Poster (PDF Preview)", visible=False)
with gr.Row():
pdf_file_out = gr.File(label="📄 Download Poster (PDF)", interactive=False, visible=True)
zip_out = gr.File(label="📦 Download Results (.zip)", interactive=False, visible=True)
gr.Markdown("The ZIP can be uploaded to Overleaf and compiled with XeLaTeX.")
overleaf_out = gr.HTML(label="Open in Overleaf")
# Debug (hidden)
debug_zip_btn= gr.Button("🐞 Test repo output.zip", variant="secondary", visible=False)
debug_zip_out= gr.HTML(label="🐞 Real Output Preview", visible=False)
debug_zip_img= gr.Image(label="🐞 Real Output Image", interactive=False, visible=False)
debug_zip_pdfpath = gr.Textbox(visible=False)
debug_last_btn= gr.Button("🐞 Test last pipeline zip", variant="secondary", visible=False)
debug_last_out= gr.HTML(label="🐞 Last Pipeline Preview", visible=False)
debug_last_img= gr.Image(label="🐞 Last Output Image", interactive=False, visible=False)
debug_last_pdfpath = gr.Textbox(visible=False)
_run_evt = run_btn.click(
fn=run_pipeline,
inputs=[arxiv_in, pdf_in, key_in, inst_logo_in, conf_logo_in, theme_in],
outputs=[logs_out, pdf_out, pdf_file_out, zip_out, overleaf_out],
)
_run_evt.then(fn=preview_image_from_pdf, inputs=[pdf_file_out], outputs=[img_out])
_dz = debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out, debug_zip_pdfpath])
_dz.then(fn=preview_image_from_pdf, inputs=[debug_zip_pdfpath], outputs=[debug_zip_img])
_dl = debug_last_btn.click(fn=debug_compile_last_pipeline_zip, inputs=[], outputs=[debug_last_out, debug_last_pdfpath])
_dl.then(fn=preview_image_from_pdf, inputs=[debug_last_pdfpath], outputs=[debug_last_img])
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)
|