Spaces:
Running
Running
File size: 79,976 Bytes
ccfef4b d501367 0e3899e 3ea43ac f6b99fb 1e0f32b a70c0d7 9f9e345 8b3a610 9f9e345 8b3a610 9f9e345 8ed688a 9f9e345 c9f23c6 5437580 3ce5100 a62aeb0 7ac5008 a62aeb0 7ac5008 9f9e345 c9f23c6 9f9e345 c9f23c6 9f9e345 f6b99fb 9f9e345 c0090b4 f6b99fb 3ce5100 9f9e345 c9f23c6 8b3a610 c9f23c6 cadfa41 c9f23c6 cd6691f 3ce5100 cd6691f 3ce5100 f409da7 8b3a610 3ce5100 cd6691f 3ce5100 cd6691f 3ce5100 cd6691f 3ce5100 cd6691f 3ce5100 cd6691f 8b3a610 f409da7 8b3a610 f409da7 8b3a610 f409da7 c9f23c6 3ce5100 f409da7 3ce5100 f409da7 3ce5100 1e0f32b cd6691f c9f23c6 8ed688a cd6691f 3ce5100 cd6691f 3ce5100 cd6691f 8ed688a 3ce5100 cd6691f f409da7 8b3a610 cd6691f f409da7 8b3a610 8ed688a cd6691f 8ed688a c9f23c6 9f9e345 c9f23c6 05fc5be c9f23c6 9f9e345 c9f23c6 8ed688a 3ce5100 cd6691f 3ce5100 cd6691f 3ce5100 8b3a610 cd6691f c9f23c6 20dfe26 7ac5008 c9f23c6 cadfa41 f6b99fb 9f9e345 c9f23c6 3ce5100 c9f23c6 05fc5be 1e0f32b 8ed688a 3ce5100 9f9e345 c9f23c6 8ed688a 05fc5be 8ed688a 05fc5be 3ce5100 1e0f32b 8ed688a 1e0f32b 3ce5100 1e0f32b 8ed688a c9f23c6 9f9e345 3ce5100 9f9e345 c9f23c6 9f9e345 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a 9f9e345 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 8ed688a c9f23c6 2fae5f2 c9f23c6 c0090b4 c9f23c6 c0090b4 cadfa41 c9f23c6 cadfa41 c9f23c6 cadfa41 c0090b4 9f9e345 c0090b4 9f9e345 c0090b4 c9f23c6 c0090b4 c9f23c6 c0090b4 f6b99fb 9f9e345 f6b99fb cadfa41 c9f23c6 9f9e345 a62aeb0 f6b99fb a62aeb0 f6b99fb c9f23c6 f6b99fb c9f23c6 a62aeb0 f6b99fb c9f23c6 f6b99fb cadfa41 f6b99fb 9f9e345 62609ce 7404e05 9f9e345 8ed688a c9f23c6 9f9e345 c9f23c6 7ac5008 cd6691f c9f23c6 8ed688a 5437580 8ed688a c9f23c6 9f9e345 c9f23c6 9f9e345 5437580 f6b99fb 5437580 f6b99fb c9f23c6 414c8d5 c9f23c6 cadfa41 414c8d5 cadfa41 c9f23c6 5437580 3053a9b 8ed688a c9f23c6 414c8d5 05fc5be c9f23c6 3ce5100 a62aeb0 c9f23c6 3ce5100 c9f23c6 3ce5100 f409da7 3ce5100 f409da7 3ce5100 7ac5008 3ce5100 7ac5008 3ce5100 a62aeb0 8ed688a a62aeb0 414c8d5 7864509 7ac5008 c9f23c6 cadfa41 a62aeb0 c9f23c6 62609ce c9f23c6 cadfa41 a62aeb0 c9f23c6 cadfa41 c9f23c6 a62aeb0 c9f23c6 414c8d5 c9f23c6 7ac5008 414c8d5 c9f23c6 5437580 8ed688a 05fc5be 8ed688a 05fc5be 8ed688a 05fc5be 8ed688a 05fc5be 8ed688a 05fc5be a62aeb0 c9f23c6 f879749 c9f23c6 414c8d5 a62aeb0 c9f23c6 414c8d5 c9f23c6 7ac5008 414c8d5 a62aeb0 c9f23c6 a62aeb0 042c305 a62aeb0 042c305 a62aeb0 042c305 773ccf0 8ed688a 773ccf0 218ec5b 042c305 41c4e1b 9f9e345 10be047 414c8d5 9f9e345 414c8d5 a62aeb0 773ccf0 9f9e345 5437580 67ad677 414c8d5 9f9e345 c9f23c6 a62aeb0 7ac5008 8ed688a a62aeb0 773ccf0 d5de09c fe5092e c9f23c6 a62aeb0 9f9e345 a62aeb0 c9f23c6 a62aeb0 9f9e345 a62aeb0 c9f23c6 a62aeb0 c9f23c6 a62aeb0 9f9e345 c9f23c6 a62aeb0 9f9e345 a62aeb0 9f9e345 a62aeb0 c9f23c6 05fc5be 8ed688a c9f23c6 a62aeb0 c9f23c6 a62aeb0 9f9e345 8ed688a 9f9e345 05fc5be a62aeb0 05fc5be 8ed688a 05fc5be 8ed688a 05fc5be 8ed688a 9f9e345 c9f23c6 a62aeb0 042c305 8ed688a 218ec5b 0d64641 1e0f32b | 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 | import gradio as gr
import json
import os
import difflib
import re
import html
import threading
# ============================================================================
# VoiceScript-AI v158.3 โ ๋จ์ด์ฅ ์ต๊ฐํ (์ธ๋ถ ํ ํฌ๋์ด์ ๋ฏธ์ฌ์ฉ)
# ============================================================================
# [2026-10-19 v158.x ์ด๋ ฅ]
# - v152: ์์ ํ๊ธ ํค ์ข์ธก ๊ฒฝ๊ณ ๊ฐ๋ ('ํด๋ฆฌ์์คํฐ' ํฉ์ฑ์ด ์คํ ์ ๊ฑฐ)
# - v153: ์์ธ ๋จ์ด(ํ์ดํธ๋ฆฌ์คํธ) UI ์ถ๊ฐ
# - v154: Kiwi ํํ์ ๊ฒฝ๊ณ ๊ฐ๋(์กฐ์ฌ ๋ฆฌ์คํธ ํด๋ฐฑ) โ '์์ค์ปฌ๋ ์ดํฐ' ๋ณด์กด
# - v155: ์๊ธฐ์นํ(k==v) โ ํ์ดํธ๋ฆฌ์คํธ ์๋ ๋ฏธ๋ฌ๋ง
# - v156: ๊ตฌ๋์ ์ ์ฐ ๋งค์นญ (๋ฑ๋ก ํค์ ๋์ด์ฐ๊ธฐ/๋ง์นจํ ์ฐจ์ด ํก์)
# - v157: ์๊ธฐ์นํโํ์ดํธ๋ฆฌ์คํธ ์๋ฐฉํฅ ๋๊ธฐํ(auto_whitelist.json)
# - v158: ๋ฐ์ ์คํ ๊ฐ์ง(์์ ์ถฉ๋) + ๊ฒน์นจ ๊ฐ์ง(๊ธฐ์กด ๋จ์ด์ฅ ์ญ์ ์์)
# - v158.1~3: ๊ท์น-์์ธ ์ถฉ๋ ํ์(์๋ฐฉํฅ ๊ฒน์นจ, ๋ถํ
์ ์๋ ์ ๋ฆฌ)
# [2026-08-29]
# - ์ธ๋ถ ํ์ฌ ํ ํฌ๋์ด์ ์์กด์ฑ ์์ ์ ๊ฑฐ. ๋์ด์ฝ๊ธฐ๋ ๋จ์ด์ฅ ๊ธฐ๋ฐ ํ๊ธฐ ์ ๊ทํ
# + ๋ฌธ์ฅ๋ถํธ ํธํก์ (`, ` ๋ค์ `/`, ๋ฌธ์ฅ ๋์์ `\n\n`)์ผ๋ก๋ง ๋ง๋ ๋ค.
# - ์๋ ๋ฐ์ ์ฌ์ 172๊ฐ (์ฌ์ฉ์ ํค ๋ฑ๋ก๊ฐ ์ฐ์ โ ๋นํ๊ดด ๋ณํฉ).
# - ์ค๋์ค ์์ฑ ์ฝ๋(edge-ttsยทgTTSยทAudio ์์ ฏ) ์์ ์ ๊ฑฐ โ ๋๋ณธ ๋ณํ ์ ์ฉ ์ฑ.
# - ๋จ์ด์ฅ ์ ๊ท 60๊ฐ ์ถ๊ฐ(์๋ฌธ ์ฝ์ดยท์นดํยท์ฑยท๋จ์ยท์ฌ์ด์ฆยท๊ธฐ๊ฐยท์์ผ).
# - ๋ฒํผ ํ์ ๊ฐ์ scaleยทsize๋ก ํต์ผ. ์ด๊ธฐํ ๋ฒํผ์ ๋ง์ง๋ง ์๋ฆฌ๋ก ๋ณต์.
# ============================================================================
# ---------- [v154] ํํ์ ๊ฒฝ๊ณ ์ธ์ (A+B ํ์ด๋ธ๋ฆฌ๋) ----------
# B: Kiwi(๊ฒฝ๋ ํํ์ ๋ถ์๊ธฐ, ์์ ํ ) โ ์์ผ๋ฉด ์กฐ์ฌ/์ด๋ฏธ ๊ฒฝ๊ณ๋ฅผ ์ ๋ฐ ํ๋ณ
# A: Kiwi๊ฐ ์๊ฑฐ๋ ๋ก๋ ์คํจ ์ ์กฐ์ฌ ์ ๋ฏธ์ฌ ๋ฆฌ์คํธ๋ก ํด๋ฐฑ (์์กด์ฑ 0, ์ฑ์ ์ ๋ ์ ์ฃฝ์)
_kiwi = None
_KIWI_OK = None # None=์์ง ์๋ ์ ํจ / True / False
def _load_kiwi():
global _kiwi, _KIWI_OK
if _KIWI_OK is None:
try:
from kiwipiepy import Kiwi
_kiwi = Kiwi()
_KIWI_OK = True
print("[ํํ์ ๋ถ์๊ธฐ] Kiwi ๋ก๋ ์๋ฃ โ ์กฐ์ฌ/์ด๋ฏธ ๊ฒฝ๊ณ ํ๋ณ ์ฌ์ฉ")
except Exception as e:
_KIWI_OK = False
print(f"[ํํ์ ๋ถ์๊ธฐ] Kiwi ๋ก๋ ์คํจ({e}) โ ์กฐ์ฌ ๋ฆฌ์คํธ ๊ท์น์ผ๋ก ํด๋ฐฑ")
return _kiwi
# A ํด๋ฐฑ์ฉ: ์ด์ ๋ค์ ๋ถ๋ ํ๊ตญ์ด ์กฐ์ฌยท๋ณด์กฐ์ฌยท์ด๋ฏธ (๊ธธ์ด ๋ด๋ฆผ์ฐจ์ โ ๊ธด ๊ฒ ๋จผ์ )
_PARTICLE_SUFFIXES = sorted(set([
"์ผ๋ก๋ถํฐ", "๋ก๋ถํฐ", "์์", "์๊ฒ", "ํํ
", "๊น์ง", "๋ณด๋ค", "์ฒ๋ผ", "๊ฐ์ด",
"๋งํผ", "์กฐ์ฐจ", "๋ง์ ", "ํ๊ณ ", "์ด๋", "์ด๋ผ", "์
๋๋ค", "์ด์ง๋ง", "๋๊น",
"๋๋ฐ", "๋", "์", "์ด", "๊ฐ", "์", "๋ฅผ", "์", "์", "๋", "๋ง",
"๊ณผ", "์", "๋ก", "์ผ", "์ผ", "์", "๊ป", "๋"
]), key=lambda x: -len(x))
class _MorphBoundary:
"""ํ์ฌ ํ
์คํธ ๊ธฐ์ค ํํ์ ๊ฒฝ๊ณ โ ํค ๋งค์นญ ์์น ๋ค๊ฐ '์กฐ์ฌ/์ด๋ฏธ์ ์์'์ธ์ง ํ๋ณ."""
def __init__(self, text):
self.text = text or ""
self._kiwi = _load_kiwi()
self._starts = {} # position -> tag (Kiwi ํ ํฐ ์์์ )
if self._kiwi is not None:
try:
for tok in self._kiwi.tokenize(self.text):
st = int(tok.start) if tok.start is not None else None
if st is not None and st not in self._starts:
self._starts[st] = tok.tag
except Exception:
self._kiwi = None
@staticmethod
def _is_particle_tag(tag):
# J*: ์กฐ์ฌ / E*: ์ด๋ฏธ / VCPยทVCN: '์ด๋คยท์๋๋ค' ๋ฅ (์: ์์ค์
๋๋ค)
return tag.startswith("J") or tag.startswith("E") or tag in ("VCP", "VCN")
def allow_after(self, e):
"""ํค ๋งค์นญ์ด ๋๋ ์์น e ๋ค์ ์กฐ์ฌ/์ด๋ฏธ(์ ํํ์)๊ฐ ์ด์ด์ง๋ฉด True."""
if e is None or e >= len(self.text):
return True
nxt = self.text[e]
if not ('๊ฐ' <= nxt <= 'ํฃ'): # ๊ณต๋ฐฑยท๋ฌธ์ฅ๋ถํธยท๋ โ ๋
๋ฆฝ ๋จ์ด
return True
if self._kiwi is not None and self._starts:
tag = self._starts.get(e)
if tag is not None:
return self._is_particle_tag(tag)
return False # ํ๊ธ ์ฐ์์ธ๋ฐ ํํ์ ๊ฒฝ๊ณ ์์ โ ํฉ์ฑ์ด
# ํด๋ฐฑ A: ์กฐ์ฌ ์ ๋ฏธ์ฌ๋ก ์์ํ๋์ง (Kiwi ์์ ๋๋ง)
return any(self.text[e:].startswith(p) for p in _PARTICLE_SUFFIXES)
# ---------- G2P ์๋ ์ ํ (g2pk โ g2pk2 โ g2pkk) ----------
g2p = None
G2P_BACKEND = "์์"
for _mod in ("g2pk", "g2pk2", "g2pkk"):
try:
_m = __import__(_mod, fromlist=["G2p"])
g2p = _m.G2p()
G2P_BACKEND = _mod
print(f"G2P ๋ก๋ฉ ์๋ฃ: {_mod}")
break
except Exception as _e:
print(f"G2P {_mod} ๋ก๋ฉ ์คํจ: {_e}")
dict_path = "custom_dict.json"
whitelist_path = "custom_whitelist.json" # [v153] ์์ธ ๋จ์ด(์นํ ๊ธ์ง) โ ์ฌ์ฉ์ ์๋ ๋ฑ๋ก
auto_wl_path = "auto_whitelist.json" # [v157] ์ฌ์ ์๊ธฐ์นํ์์ ์๋ ๋ฏธ๋ฌ๋ง๋ ํญ๋ชฉ (๋๊ธฐํ ๊ด๋ฆฌ ๋์)
ADMIN_ID = os.environ.get("ADMIN_ID", "admin")
ADMIN_PW = os.environ.get("ADMIN_PW", "admin1234")
GUEST_ID = os.environ.get("GUEST_ID", "guest")
GUEST_PW = os.environ.get("GUEST_PW", "guest1234")
# ---------- HF Dataset ์๊ตฌ ์ ์ฅ์ (์ ํ) ----------
HF_TOKEN = os.environ.get("HF_TOKEN")
DICT_REPO = os.environ.get("DICT_REPO", "").strip()
hf_api = None
dict_repo_id = None
SYNC_STATE = "๋ก์ปฌ ์ ์ฉ (HF_TOKEN ๋ฏธ์ค์ โ Space ์ฌ์์ ์ ๋ฑ๋ก๋ถ ์ ์ค!)"
try:
from huggingface_hub import HfApi, hf_hub_download
if HF_TOKEN:
hf_api = HfApi(token=HF_TOKEN)
dict_repo_id = DICT_REPO or (hf_api.whoami()["name"] + "/voicescript-dict")
hf_api.create_repo(dict_repo_id, repo_type="dataset", private=True, exist_ok=True)
SYNC_STATE = f"์๊ตฌ ์ ์ฅ์ ์ฐ๊ฒฐ๋จ: {dict_repo_id}"
except Exception as _e:
hf_api = None
SYNC_STATE = f"์๊ตฌ ์ ์ฅ์ ์ฐ๊ฒฐ ์คํจ({_e}) - ๋ก์ปฌ ์ ์ฅ๋ง ๋์"
print(f"[์ฌ์ ์ ์ฅ์] {SYNC_STATE}")
# ============================================================================
# AUTO_MERGE_WORDS โ ์๋ ๋ฐ์ ์ฌ์
# ์ฌ์ฉ์ ์ฌ์ ์ ๊ฐ์ ํค๊ฐ ์ด๋ฏธ ์์ผ๋ฉด setdefault ๋๋ถ์ ๋ฎ์ด์ฐ์ง ์์.
# ============================================================================
AUTO_MERGE_WORDS = [
# โโ ์๋ฌธ ์ฝ์ดยท๋ธ๋๋ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["H&M", "์์ด์น ์ค ์ "],
["ZARA", "์๋ผ"],
["UNIQLO", "์ ๋ํด๋ก"],
["YouTube", "์ ํ๋ธ"],
["Instagram", "์ธ์คํ๊ทธ๋จ"],
["iPhone", "์์ดํฐ"], ["iOS", "์์ด์ค์์ค"], ["IOS", "์์ด์ค์์ค"],
["Android", "์๋๋ก์ด๋"],
["Mac", "๋งฅ"], ["MacBook", "๋งฅ๋ถ"],
["Windows", "์๋์ฐ"],
["NAVER", "๋ค์ด๋ฒ"], ["DAUM", "๋ค์"], ["KAKAO", "์นด์นด์ค"],
["CJ", "์จ์ ์ด"], ["HD", "์์ด์น๋"], ["LS", "์์์ค"],
["LG", "์์ง"], ["SK", "์์ค์ผ์ด"], ["KT", "์ผ์ดํฐ"],
["26SS", "์ด์ญ์ก ์์ค์์ค"], ["26 SS", "์ด์ญ์ก ์์ค์์ค"],
["26S/S", "์ด์ญ์ก ์์ค์์ค"], ["26 S/S", "์ด์ญ์ก ์์ค์์ค"],
["25SS", "์ด์ญ์ค ์์ค์์ค"], ["25 SS", "์ด์ญ์ค ์์ค์์ค"],
["FW", "์ํ๋๋ธ์ "], ["SSFW", "์์ค์์ค ์ํ๋๋ธ์ "],
["GS๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"], ["GS ๋ง์ด์ต", "์ง์์ค๋ง์ด์ต"],
["GS์ต", "์ง์์ค์ต"], ["GS ์ต", "์ง์์ค์ต"],
# โโ ์นดํยท์ฑยท์๋น์ค โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["์นด์นด์คํก", "์นด์นด์ค ํก"],
["๋ฐฐ๋ฌ์๋ฏผ์กฑ", "๋ฐฐ๋ฌ์ ๋ฏผ์กฑ"],
["๋น๊ทผ๋ง์ผ", "๋น๊ทผ ๋ง์ผ"],
["ํ ์ค", "ํ ์ค"], ["์ฟ ํก", "์ฟ ํก"],
["๋ค์ด๋ฒ", "๋ค์ด๋ฒ"], ["๋ค์", "๋ค์"], ["์ค", "์ค"],
# โโ ์ซ์+๋จ์ ๊ฒฐํฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["14์ธ์น", "์ญ์ฌ ์ธ์น"],
["13.3์ธ์น", "์ญ์ผ ์ ์ผ ์ธ์น"],
["15์ธ์น", "์ญ์ค ์ธ์น"], ["15.6์ธ์น", "์ญ์ค ์ ์ก ์ธ์น"],
["32GB", "์ผ์ญ์ด ๊ธฐ๊ฐ"], ["64GB", "์ก์ญ์ฌ ๊ธฐ๊ฐ"], ["128GB", "๋ฐฑ์ด์ญํ ๊ธฐ๊ฐ"],
["256GB", "์ด๋ฐฑ์ค์ญ์ก ๊ธฐ๊ฐ"], ["512GB", "์ค๋ฐฑ์ญ์ด ๊ธฐ๊ฐ"],
["1TB", "์ผ ํ
๋ผ๋ฐ์ดํธ"],
["1080p", "์ฒํ์ญ ํผ"], ["4K", "ํฌ ์ผ์ด"], ["8K", "์์ ์ผ์ด"],
# โโ ๋จ์ ๋ณด์ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["์ธ์น", "์ธ์น"], ["์ผ๋", "์ผ๋"], ["ํ์ด๋", "ํ์ด๋"],
["์จ์ค", "์จ์ค"], ["๊ฐค๋ฐ", "๊ฐค๋ฐ"], ["์จ๋", "์จ๋"],
["ํฅํ๋ฅด", "ํฅํ๋ฅด"], ["๋ฐ์๋ฆฌํฐ", "๋ฐ์๋ฆฌํฐ"], ["๋ง์ผ", "๋ง์ผ"],
["๋
ธํธ", "๋
ธํธ"],
["mm", "๋ฐ๋ฆฌ๋ฏธํฐ"], ["cm", "์ผํฐ๋ฏธํฐ"], ["km", "ํฌ๋ก๋ฏธํฐ"],
["kg", "ํฌ๋ก๊ทธ๋จ"], ["mg", "๋ฐ๋ฆฌ๊ทธ๋จ"], ["ml", "๋ฐ๋ฆฌ๋ฆฌํฐ"],
# โโ ์๋ฌธ ์๋ฅ ์ฌ์ด์ฆ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["XS", "์์ค์ค"], ["S", "์์ค"], ["M", "์ "], ["L", "์"],
["XL", "์์ค์"], ["XXL", "๋๋ธ์์ค์"],
["FREE", "ํ๋ฆฌ"], ["ONE SIZE", "์ ์ฌ์ด์ฆ"],
# โโ ํ์ซ์ ์ฌ์ด์ฆ(ํ๊ตญ ์๋ฅ ์ฌ์ด์ฆ) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["55์ฌ์ด์ฆ", "์ค์ค ์ธ์ด์ฆ"], ["55 ์ฌ์ด์ฆ", "์ค์ค ์ธ์ด์ฆ"],
["66์ฌ์ด์ฆ", "์ต์ก ์ธ์ด์ฆ"], ["66 ์ฌ์ด์ฆ", "์ต์ก ์ธ์ด์ฆ"],
["77์ฌ์ด์ฆ", "์น ์น ์ธ์ด์ฆ"], ["77 ์ฌ์ด์ฆ", "์น ์น ์ธ์ด์ฆ"],
["88์ฌ์ด์ฆ", "ํํ ์ธ์ด์ฆ"], ["88 ์ฌ์ด์ฆ", "ํํ ์ธ์ด์ฆ"],
["95์ฌ์ด์ฆ", "๊ตฌ์ค ์ธ์ด์ฆ"], ["95 ์ฌ์ด์ฆ", "๊ตฌ์ค ์ธ์ด์ฆ"],
["100์ฌ์ด์ฆ", "๋ฐฑ ์ธ์ด์ฆ"], ["100 ์ฌ์ด์ฆ", "๋ฐฑ ์ธ์ด์ฆ"],
["105์ฌ์ด์ฆ", "๋ฐฑ์ค ์ธ์ด์ฆ"], ["105 ์ฌ์ด์ฆ", "๋ฐฑ์ค ์ธ์ด์ฆ"],
["110์ฌ์ด์ฆ", "๋ฐฑ์ญ ์ธ์ด์ฆ"], ["110 ์ฌ์ด์ฆ", "๋ฐฑ์ญ ์ธ์ด์ฆ"],
["๋จ๋
์ฌ์ด์ฆ", "๋จ๋
์ฌ์ด์ฆ"], ["๋จ๋
์ฌ์ด์ฆ", "๋จ๋
์ฌ์ด์ฆ"],
# โโ %, 100% โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["100%", "๋ฐฑํ๋ก"], ["100 %", "๋ฐฑํ๋ก"], ["100ํ๋ก", "๋ฐฑํ๋ก"],
["50%", "์ค์ญํ๋ก"], ["50 %", "์ค์ญํ๋ก"],
["20%", "์ด์ญํ๋ก"], ["20 %", "์ด์ญํ๋ก"],
["30%", "์ผ์ญํ๋ก"], ["30 %", "์ผ์ญํ๋ก"],
["90%", "๊ตฌ์ญํ๋ก"], ["90 %", "๊ตฌ์ญํ๋ก"],
# โโ ๊ฐ๊ฒฉ (์ฝค๋ง ์๋ ๊ฒ ์ฐ์ โ ์ผ๋ฐ ๊ฒ ์ฐจํ) โโโโโโโโโโโโโโโโโโโโโโ
["99,000์", "๊ตฌ๋ง ๊ตฌ์ฒ ์"], ["99,000 ์", "๊ตฌ๋ง ๊ตฌ์ฒ ์"],
["59,900์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["59,900 ์", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["49,900์", "์ฌ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["49,900 ์", "์ฌ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["39,900์", "์ผ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["39,900 ์", "์ผ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["29,900์", "์ด๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["29,900 ์", "์ด๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["19,900์", "์ผ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["19,900 ์", "์ผ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["9,900์", "๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"], ["9,900 ์", "๊ตฌ์ฒ๊ตฌ๋ฐฑ ์"],
["59,900", "์ค๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ"], ["49,900", "์ฌ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ"],
["39,900", "์ผ๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ"], ["29,900", "์ด๋ง ๊ตฌ์ฒ๊ตฌ๋ฐฑ"],
# โโ ๊ธฐ๊ฐ (์ผ๋ฐ ์ผ/์ฃผ/๋
) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["1์ผ", "ํ๋ฃจ"], ["2์ผ", "์ดํ"], ["3์ผ", "์ฌํ"],
["1์ฃผ", "์ผ์ฃผ"], ["2์ฃผ", "์ด์ฃผ"], ["1๋
", "์ผ๋
"],
["24์๊ฐ", "์ด์ญ์ฌ ์๊ฐ"], ["12์๊ฐ", "์ญ์ด ์๊ฐ"],
["3๊ฐ์", "์ผ๊ฐ์"], ["3 ๊ฐ์", "์ผ๊ฐ์"],
["6๊ฐ์", "์ก๊ฐ์"], ["6 ๊ฐ์", "์ก๊ฐ์"],
["12๊ฐ์", "์ญ์ด๊ฐ์"], ["12 ๊ฐ์", "์ญ์ด๊ฐ์"],
["24๊ฐ์", "์ด์ญ์ฌ๊ฐ์"], ["24 ๊ฐ์", "์ด์ญ์ฌ๊ฐ์"],
# โโ ์๊ฐยท์์ผ ํ๊ธฐ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["์ค์ ", "์ค์ "], ["์คํ", "์คํ"],
["AM", "์์ด์ "], ["PM", "ํผ์ "], ["KST", "์ผ์ด์์คํฐ"],
["์์์ผ", "์์์ผ"], ["ํ์์ผ", "ํ์์ผ"], ["ํ์ผ", "ํ์ผ"],
# โโ ๊ฐ๊ฒฉ๋ ํํ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["1๋ง์๋", "๋ง์๋"], ["1๋ง ์๋", "๋ง์๋"],
["1๋ง ์ ๋", "๋ง์๋"], ["1๋ง์ ๋", "๋ง์๋"],
["2๋ง์๋", "์ด๋ง์๋"], ["2๋ง ์๋", "์ด๋ง์๋"],
["3๋ง์๋", "์ผ๋ง์๋"], ["3๋ง ์๋", "์ผ๋ง์๋"],
["5๋ง์๋", "์ค๋ง์๋"], ["5๋ง ์๋", "์ค๋ง์๋"],
# โโ ์์ฃผ ํ๋ฆฌ๋ ํ๊ตญ์ด ํ๊ธฐ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
["~์
๋๋ค", "~์ต๋๋ค"], ["์
๋๋ค", "์
๋๋ค"],
["์์ ์
๋๋ค", "์์ ์
๋๋ค"], ["๊ฒฐ๊ณผ์ ์ผ๋ก", "๊ฒฐ๊ณผ์ ์ผ๋ก"],
["์ผ์ฑ", "์ผ์ฑ"], ["ํ๋", "ํ๋"], ["๊ธฐ์", "๊ธฐ์"],
["์ํ", "์ํ"], ["์ ํ", "์ ํ"], ["๊ฐ๊ฒฉ", "๊ฐ๊ฒฉ"],
["๋ฐฐ์ก", "๋ฐฐ์ก"], ["ํ ์ธ", "ํ ์ธ"], ["์ด๋ฒคํธ", "์ด๋ฒคํธ"]
]
# ---------- [v158] ๋ฑ๋ก ๋ณด์กฐ: ๋ฐ์ ์คํ ๊ฐ์ง + ์ค๋ณต(์๋ฆฐ) ํค ์๋ ์ ๋ฆฌ ----------
def _detect_pronun_typo(word, pronun):
"""[v158] ๋ฐ์ ํ๊ธฐ์ ํํ ์คํ๋ฅผ ๊ฐ์งํด ๊ฒฝ๊ณ ๋ฌธ์์ด ๋ชฉ๋ก์ ๋ฐํ.
1) ์์ ์ถฉ๋: ํ๊ธ ์ข
์ฑ(๋ฐ์นจ) ๋ฐ๋ก ๋ค์ ๊ฐ์ ์์๊ณ ์ด์ฑ์ด ๋ถ์ผ๋ฉด
'์ต๋น'๋ฅ์ ๋ถ์์ฐ์ค๋ฌ์ด ๋ฐ์ ํ๊ธฐ์ผ ๊ฐ๋ฅ์ฑ์ด ๋๋ค.
2) ์๊ธฐ์นํ: ๋จ์ด์ ๋ฐ์์ด ์์ ํ ๊ฐ์ผ๋ฉด ๋ฐ์ ์ง์ ์๋ฏธ๊ฐ ์๋ค(์์ธ ๋ฑ๋ก ์ทจ์ง ์ ์ธ)."""
warnings = []
if pronun == word:
warnings.append("๋จ์ด์ ๋ฐ์์ด ๋๊ฐ์ต๋๋ค. ์ด๋๋ก ์ ์ฅํ๋ฉด ์ด ๋จ์ด๋ ์ด๋ค ๋ฐ์ ๋ณํ๋ ๋ฐ์ง ์์ต๋๋ค(์๋ฌธ ์ ์ง).")
# ์ข
์ฑ-์ด์ฑ ์์ ์ถฉ๋ ์ค์บ: ๊ฒน๋ฐ์นจ ํฌํจ ์ข
์ฑ ๋ค์ ๋์ผ ๊ณ์ด ์์ ์ด์ฑ์ด ์ค๋ ์กฐํฉ
_jamO_conflict = [
("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใฑ", "ใฑ"), ("ใฑ", "ใฒ"),
("ใฑ", "ใ
"), ("ใท", "ใท"), ("ใท", "ใธ"), ("ใท", "ใ
"), ("ใ
", "ใ
"),
("ใด", "ใด"), ("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใน", "ใน"), ("ใ
", "ใ
"),
("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใ
", "ใ
"), ("ใ
", "ใ
"),
]
_cho = "ใฑใฒใดใทใธในใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
ใ
"
_jong_map = { # ์ข
์ฑ โ ๋ํ ์์
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: 'ใ
',
}
prev_jong = None
for ch in pronun:
if '๊ฐ' <= ch <= 'ํฃ':
offset = ord(ch) - ord('๊ฐ')
jong = offset % 28 # 0=๋ฐ์นจ ์์, 1~27
cho_idx = offset // (21 * 28)
if prev_jong is not None and cho_idx < len(_cho):
cur_cho = _cho[cho_idx]
cur_jong = _jong_map.get(prev_jong) # prev_jong: 1~27 ์ธ๋ฑ์ค โ ๋ํ ์์ ๋ฌธ์
if cur_jong and any(j == cur_jong and c == cur_cho for j, c in _jamO_conflict):
ctx = pronun[max(0, pronun.find(ch) - 1):pronun.find(ch) + 2]
warnings.append(f"๋ฐ์์ ๋ถ์์ฐ์ค๋ฌ์ด ์์ ์ถฉ๋์ด ์์ต๋๋ค: '...{ctx}...' โ ์ค์ ๋ญ๋
๋ฐ์(์: '๋ง์ด์ต์
๋๋ค'โ'๋ง์ด์ค๋น๋๋ค')์ธ์ง ๋ค์ ํ์ธํ์ธ์.")
break
prev_jong = jong if jong > 0 else None
else:
prev_jong = None
return list(dict.fromkeys(warnings))[:2] # ์ต๋ 2๊ฐ, ์ค๋ณต ์ ๊ฑฐ
def _find_overlapping_keys(dict_map, new_word):
"""[v158-final] ์ ํค์ '๊ฐ์ ๋จ์ด์ ๋ค๋ฅธ ํ๊ธฐ'๋ก ๊ฒน์น๋ ๊ธฐ์กด ํค๋ฅผ ์ฐพ๋๋ค.
์ ๋ ์ญ์ ํ์ง ์๋๋ค โ ์์ง์ด ๊ธด ํค ์ฐ์ ๋งค์นญ์ ํ๋ฏ๋ก ์ฐ์ ์์๋ ์ด๋ฏธ ๋ณด์ฅ๋๊ณ ,
๊ธฐ์กด์ ๋ฑ๋ก๋ ๋จ์ด์ฅ์ ์ด๋ค ๊ฒฝ์ฐ์๋ ํผ์๋์ง ์์์ผ ํ๊ธฐ ๋๋ฌธ(์ฌ์ฉ์ ์๊ตฌ).
- ๊ฒน์นจ ํ์ : ๊ณต๋ฐฑ์ ๋ฌด์ํ๊ณ ํ์ชฝ์ด ๋ค๋ฅธ ์ชฝ์ ์ ๋์ด(4๊ธ์ ์ด์).
'์ง์์ค๋ง์ด์ต์
๋๋ค' vs '์ง์์ค ๋ง์ด์ต์
๋๋ค' (๋์ด์ฐ๊ธฐ ์ฐจ์ด)๋ ๊ฒน์นจ์ผ๋ก ๋ณธ๋ค.
๋ฐํ: ๊ฒน์น๋ ๊ธฐ์กด ํค ๋ชฉ๋ก."""
def _norm(s):
return re.sub(r'\s+', '', s or "")
nw = _norm(new_word)
if len(nw) < 4:
return []
overlaps = []
for k in dict_map.keys():
if k == new_word:
continue
nk = _norm(k)
if len(nk) < 4:
continue
if nk.startswith(nw) or nw.startswith(nk):
overlaps.append(k)
return overlaps
# ---------- ์ฌ์ I/O ----------
def _read_local_dict():
try:
with open(dict_path, "r", encoding="utf-8") as f:
data = json.load(f)
return {i[0].strip(): i[1].strip() for i in data.get("items", []) if len(i) == 2}
except Exception:
return {}
def _write_local_dict(dict_map):
items = [[k, v] for k, v in dict_map.items()]
payload = {"items": items, "meta": {"app_title": "VoiceScript AI", "app_version": "158.3", "count": len(items)}}
tmp_path = dict_path + ".tmp"
with open(tmp_path, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=2)
if os.path.exists(dict_path):
os.replace(dict_path, dict_path + ".bak")
os.replace(tmp_path, dict_path)
def _push_remote():
if not hf_api:
return "๋ก์ปฌ ์ ์ฅ๋ง ๋จ (์ฌ์์ ์ ์ ์ค ๊ฐ๋ฅ - HF_TOKEN ์ค์ ํ์)"
try:
hf_api.upload_file(path_or_fileobj=dict_path, path_in_repo="custom_dict.json",
repo_id=dict_repo_id, repo_type="dataset",
commit_message="update pronunciation dict")
return "์๊ตฌ ์ ์ฅ ์๋ฃ"
except Exception as e:
return f"์๊ฒฉ ์ ์ฅ ์คํจ({e}) - ๋ก์ปฌ๋ง ์ ์ฅ๋จ"
def _self_reference_keys(dict_map):
"""[v155] ์ฌ์ ์์ k == v (์๊ธฐ์นํ) ์ธ ํค ๋ชฉ๋ก.
์ฌ์ฉ์๊ฐ '์ด ๋จ์ด๋ฅผ ์๋ฌธ ๊ทธ๋๋ก ๋๊ณ ์ถ๋ค'๋ ์๋๋ก ๋ฑ๋กํ ํญ๋ชฉ๋ค."""
return [k for k, v in (dict_map or {}).items() if k and k == v]
def _read_auto_whitelist():
"""[v157] ์ฌ์ ์๊ธฐ์นํ์์ ์๋ ๋ฏธ๋ฌ๋ง๋ ํ์ดํธ๋ฆฌ์คํธ ๋ชฉ๋ก (๋๊ธฐํ ๊ด๋ฆฌ ๋์)."""
try:
with open(auto_wl_path, "r", encoding="utf-8") as f:
data = json.load(f)
return {str(x).strip() for x in data.get("items", []) if str(x).strip()}
except Exception:
return set()
def _write_auto_whitelist(items_set):
payload = {"items": sorted(items_set), "meta": {"app_title": "auto whitelist mirror",
"app_version": "157.0",
"count": len(items_set)}}
tmp = auto_wl_path + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=2)
if os.path.exists(auto_wl_path):
os.replace(auto_wl_path, auto_wl_path + ".bak")
os.replace(tmp, auto_wl_path)
def _sync_self_refs_to_whitelist(dict_map):
"""[v157] ์ฌ์ ์ ์๊ธฐ์นํ๊ณผ ํ์ดํธ๋ฆฌ์คํธ๋ฅผ ์๋ฐฉํฅ ๋๊ธฐํ.
- ์ฌ์ ์ ์๋ก ์๊ธด ์๊ธฐ์นํ์ ํ์ดํธ๋ฆฌ์คํธ์ ์ถ๊ฐ (v155 ๋์)
- ์ฌ์ ์์ ์๊ธฐ์นํ์ด ์ฌ๋ผ์ง ํญ๋ชฉ์ ํ์ดํธ๋ฆฌ์คํธ์์๋ ์ ๊ฑฐ (v157 ์ ๊ท)
๋จ, ์ฌ์ฉ์๊ฐ UI๋ก ์ง์ ๋ฑ๋กํ ํ์ดํธ๋ฆฌ์คํธ ํญ๋ชฉ์ ์ ๋ ๊ฑด๋๋ฆฌ์ง ์์
(auto_whitelist.json ์ ๊ธฐ๋ก๋ '์๋ ๋ฏธ๋ฌ๋ง ํ์ '๋ง ๊ด๋ฆฌ ๋์).
[v158] ์์ ํํฐ ์ถ๊ฐ: '์
๋๋ค' ๊ฐ์ ์ด๋จ์ ์๊ธฐ์นํ(๋ด์ฅ ์ฌ์ ์ ๋์ผ ํ๊ธฐ๋ก
๋ค์ด์๋ ๊ฒ๋ค)์ ํ์ดํธ๋ฆฌ์คํธ๋ก ๋ฏธ๋ฌ๋งํ๋ฉด ์๋ฌธ์ ํํ ์ด๋ฏธ๊น์ง ๋ง์คํน๋์ด
๊ทธ ์์ ๋ชจ๋ ์ฌ์ ๊ท์น์ด ๋งค์นญ์ ์๋๋ค(10/19 ๋ฒ๊ทธ). ๋ฐ๋ผ์
ํ์ดํธ๋ฆฌ์คํธ ์๋ ๋ฑ๋ก์ '3๊ธ์ ์ด์ + ๊ณต๋ฐฑ ํฌํจ ๋ฌธ๊ตฌ'๋ง ํ์ฉํ๋ค.
๋ฐํ: (added, removed) ํํ."""
try:
# [v158] ์๋ ๋ฏธ๋ฌ๋ง ์๊ฒฉ ํํฐ: 3๊ธ์ ์ด์(๊ณต๋ฐฑ ์ ์ธ)๋ง โ '์
๋๋ค','์ํ'๋ฅ ๋ณดํธ
def _eligible(s):
return len(re.sub(r'\s+', '', s)) >= 4
current_self_refs = {t for t in _self_reference_keys(dict_map)
if _eligible(t) and not _wl_overlaps_rules(t, dict_map)}
previously_auto = _read_auto_whitelist() # ์ด์ ์ ์๋ ๋ฏธ๋ฌ๋งํ ๋ชฉ๋ก
current_wl = set(_read_local_whitelist())
added = current_self_refs - current_wl # ์๋ก ๋ฃ์ ํญ๋ชฉ
removed = (previously_auto - current_self_refs) & current_wl # ์ฌ์ ์์ ์ฌ๋ผ์ง ์๋ ํญ๋ชฉ๋ง ์ ๊ฑฐ
# [v158] ์๊ฒฉ์ ์์ ๊ณผ๊ฑฐ ์๋ ํญ๋ชฉ๋ ํ์ (์: '์
๋๋ค'๋ฅ๊ฐ ๊ณผ๊ฑฐ์ ๋ค์ด๊ฐ ๊ฒฝ์ฐ)
removed |= (previously_auto - current_self_refs) & current_wl
removed |= {t for t in previously_auto if t in current_wl and not _eligible(t)}
if not added and not removed:
return [], []
new_wl = (current_wl | added) - removed
_write_local_whitelist(sorted(new_wl, key=lambda x: -len(x)))
# ์๋ ๋ฏธ๋ฌ๋ง ํ์ ๊ฐฑ์ = ์ง๊ธ ์ฌ์ ์ ์๋ ์๊ธฐ์นํ ์ ๋ถ
_write_auto_whitelist(current_self_refs)
if hf_api:
def _bg_push_wl():
try:
msg = _push_remote_whitelist()
print(f"[v157 ํ์ดํธ๋ฆฌ์คํธ ๋๊ธฐํ ์๊ฒฉ] {msg}")
except Exception as e:
print(f"[v157 ํ์ดํธ๋ฆฌ์คํธ ๋๊ธฐํ ์๊ฒฉ ์คํจ] {e}")
threading.Thread(target=_bg_push_wl, daemon=True).start()
if added:
print(f"[v157] ์๊ธฐ์นํ โ ํ์ดํธ๋ฆฌ์คํธ ์ถ๊ฐ {len(added)}: {sorted(added)}")
if removed:
print(f"[v157] ์๊ธฐ์นํ ํด์ โ ํ์ดํธ๋ฆฌ์คํธ ์ ๊ฑฐ {len(removed)}: {sorted(removed)}")
return sorted(added), sorted(removed)
except Exception as e:
print(f"[v157] ํ์ดํธ๋ฆฌ์คํธ ๋๊ธฐํ ์คํจ: {e}")
return [], []
# ํ์ ํธํ ๋ณ์นญ (๊ธฐ์กด ํธ์ถ๋ถ๊ฐ ์ด ์ด๋ฆ์ ์ฐธ์กฐํ๋ฏ๋ก ์ ์ง)
def _mirror_self_refs_to_whitelist(dict_map):
added, _ = _sync_self_refs_to_whitelist(dict_map)
return added
def _wl_overlaps_rules(term, dict_map):
"""[v158.3] ํ์ดํธ๋ฆฌ์คํธ ํญ๋ชฉ์ด ๋ฐ์ ๊ท์น(k!=v, 4๊ธ์+)๊ณผ ๊ฒน์น๋์ง ์๋ฐฉํฅ ํ์ .
๊ฒน์นจ = ๊ณต๋ฐฑ ์ ๊ฑฐ ํ ํ์ชฝ์ด ๋ค๋ฅธ ์ชฝ์ ๋ถ๋ถ๋ฌธ์์ด. ์ด๋ฐ ํญ๋ชฉ์ด WL์ ์์ผ๋ฉด
์๋ฌธ์ ๊ทธ ๊ตฌ๊ฐ์ด ๋ง์คํน๋์ด ํด๋น ๊ท์น์ด ์ ๋ ๋งค์นญ๋์ง ๋ชปํ๋ค."""
nt = re.sub(r'\s+', '', term or "")
if len(nt) < 2:
return False
for k, v in (dict_map or {}).items():
if not k or k == v:
continue
nk = re.sub(r'\s+', '', k)
if len(nk) < 4:
continue
if nt in nk or nk in nt:
return True
return False
def _release_conflicting_wl_terms(dict_map):
"""[v158.1] ๋ฐ์ ๊ท์น(k!=v)์ ํค์ ๊ฒน์ณ ๊ทธ ๋งค์นญ์ ๋ฐฉํดํ๋ ํ์ดํธ๋ฆฌ์คํธ ํญ๋ชฉ์
'์๋ ๋ฏธ๋ฌ๋ง ํ์ '์ ํํด์ ํ์ํ๋ค. ์ฌ์ฉ์๊ฐ UI๋ก ์ง์ ๋ฑ๋กํ ์์ธ๋ ๋ณด์กด.
๋ฐฐ๊ฒฝ: ์์ ์ค์๋ก ๋ฑ๋ก๋ ์๊ธฐ์นํ '์ง์์ค ๋ง์ด์ต'์ด ํ์ดํธ๋ฆฌ์คํธ๋ก ๋ฏธ๋ฌ๋ง๋์ด
์์ผ๋ฉด, ์ ๊ท์น '์ง์์ค ๋ง์ด์ต์
๋๋ค -> ์ง์์ค๋ง์ด์ค๋น๋๋ค'์ ํค๊ฐ ์๋ฌธ์์
๋ง์คํน๋์ด ๋งค์นญ ๊ธฐํ์กฐ์ฐจ ๋ชป ์ป๋๋ค(10/19 ์ฌ์ฉ์ ๋ฒ๊ทธ). ์๊ธฐ์นํ ์์ฒด๋
shields๋ก ๊ณ์ ๋ณดํธ๋๋ฏ๋ก ํ์ดํธ๋ฆฌ์คํธ์์ ๋น ์ ธ๋ ์๋ฌธ ์ ์ง ๊ธฐ๋ฅ์ ์ ์ง๋๋ค.
๋ฐํ: ํ์๋ ํญ๋ชฉ ๋ชฉ๋ก."""
try:
auto = _read_auto_whitelist()
wl = set(_read_local_whitelist())
rule_keys = [re.sub(r'\s+', '', k) for k, v in (dict_map or {}).items()
if k and k != v and len(re.sub(r'\s+', '', k)) >= 4]
released = []
# [v158.2] ํ์ ๋์์ ํ์ ํ์ผ์ ์์กดํ์ง ์๊ฒ ํ์ฅ โ HF Space๋ ์ฌ์์ ์
# auto_whitelist.json์ด ์ฌ๋ผ์ง๋ฏ๋ก(๋น์๊ตฌ ๋์คํฌ), ํ์ ๋ง ๋ณด๋ฉด ํ์๊ฐ ๋๋ฝ๋๋ค.
# [v158.3] ๊ฒน์นจ ํ์ ์ ์๋ฐฉํฅ์ผ๋ก โ WL ํญ๋ชฉ์ด ๊ท์น ํค๋ณด๋ค ๊ธด ๊ฒฝ์ฐ(์:
# '์๋
ํ์ธ์, ์ง์์ค ๋ง์ด์ต์
๋๋ค.')๋ ๊ทธ ๊ตฌ๊ฐ์ ๋ง์คํนํด ๊ท์น์ ๋ง์ผ๋ฏ๋ก ํ์.
# ๋์: (a) ์ฌ์ ์ ์๊ธฐ์นํ(k==v)์ผ๋ก ์กด์ฌํ๊ฑฐ๋ (b) ๊ท์น ํค์ ๊ฐ์ ๋ฌธ์์ด
# (๋์ด์ฐ๊ธฐ๋ง ๋ค๋ฆ)์ธ WL ํญ๋ชฉ โ ์ ๋ถ ์๋ ๋ฏธ๋ฌ๋ง ์ฐ๋ฌผ๋ก ๊ฐ์ฃผ. ์๊ธฐ์นํ์
# shields๊ฐ ๊ณ์ ๋ณดํธํ๋ฏ๋ก ์์ . ์ฌ์ฉ์ ์๋ ์์ธ(์ฌ์ ์ ์๋ ํญ๋ชฉ)๋ ๋ณด์กด.
norm_rule_keys = [re.sub(r'\s+', '', k) for k in dict_map
if k and dict_map[k] != k and len(re.sub(r'\s+', '', k)) >= 4]
candidates = set(auto) | {t for t in wl if dict_map.get(t) == t}
for t in wl:
if re.sub(r'\s+', '', t) in norm_rule_keys:
candidates.add(t)
for t in sorted(candidates, key=lambda x: -len(x)):
nt = re.sub(r'\s+', '', t)
if t in wl and nt and any(nt in rk or rk in nt for rk in norm_rule_keys):
wl.discard(t)
auto.discard(t)
released.append(t)
if released:
_write_local_whitelist(sorted(wl, key=lambda x: -len(x)))
_write_auto_whitelist(auto)
if hf_api:
def _bg_push_rel():
try:
msg = _push_remote_whitelist()
print(f"[v158.1 ํ์ดํธ๋ฆฌ์คํธ ํ์ ์๊ฒฉ] {msg}")
except Exception as e:
print(f"[v158.1 ํ์ดํธ๋ฆฌ์คํธ ํ์ ์๊ฒฉ ์คํจ] {e}")
threading.Thread(target=_bg_push_rel, daemon=True).start()
print(f"[v158.1] ์ ๊ท์น๊ณผ ์ถฉ๋ํ๋ ์๋ ์์ธ {len(released)}๊ฐ ํ์: {released}")
return released
except Exception as e:
print(f"[v158.1] ํ์ดํธ๋ฆฌ์คํธ ์ถฉ๋ ํ์ ์คํจ: {e}")
return []
def save_dict(dict_map):
_write_local_dict(dict_map)
_ENGINE_CACHE["sig"] = None
# [v157] ์ฌ์ ์๊ธฐ์นํ โ ํ์ดํธ๋ฆฌ์คํธ ์๋ฐฉํฅ ๋๊ธฐํ
# - ์ ์๊ธฐ์นํ: ํ์ดํธ๋ฆฌ์คํธ์ ์ถ๊ฐ (v155 ๊ธฐ๋ฅ ์ ์ง)
# - ๋ฐ์์ด ๋ฐ๋์ด ๋๋ ์๊ธฐ์นํ์ด ์๋ ํญ๋ชฉ: ํ์ดํธ๋ฆฌ์คํธ์์ ์๋ ์ ๊ฑฐ
# (์ฌ์ฉ์๊ฐ UI๋ก ์ง์ ๋ฑ๋กํ ์์ธ ๋จ์ด๋ ๊ฑด๋๋ฆฌ์ง ์์)
added_wl, removed_wl = _sync_self_refs_to_whitelist(dict_map)
released_wl = _release_conflicting_wl_terms(dict_map) # [v158.1] ๊ท์น-์์ธ ์ถฉ๋ ํด์
parts = []
if added_wl: parts.append(f"์๊ธฐ์นํ {len(added_wl)}๊ฐ ์์ธ ์๋ ๋ฑ๋ก")
if removed_wl: parts.append(f"๋ฐ์ ์์ ๋ {len(removed_wl)}๊ฐ ์์ธ ์๋ ํด์ ")
if released_wl: parts.append(f"์ ๊ท์น๊ณผ ์ถฉ๋ํ๋ ์๋ ์์ธ {len(released_wl)}๊ฐ ํ์({', '.join(released_wl[:2])}{'...' if len(released_wl) > 2 else ''})")
wl_note = (" ยท " + ", ".join(parts)) if parts else ""
# [v152] ์๊ฒฉ ์
๋ก๋๋ ์๋ต์ ๋ง์ง ์๋๋ก ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ๋ฐ์ด๋.
# ์คํจํด๋ ๋ก์ปฌ ์ ์ฅ์ ์ด๋ฏธ ์๋ฃ๋ ์ํ โ ๋ก๊ทธ๋ก๋ง ๋จ๊ธด๋ค.
if hf_api:
def _bg_push():
try:
msg = _push_remote()
print(f"[์ฌ์ ์๊ฒฉ ์ ์ฅ] {msg}")
except Exception as e:
print(f"[์ฌ์ ์๊ฒฉ ์ ์ฅ ์คํจ] {e}")
threading.Thread(target=_bg_push, daemon=True).start()
msg = "์ ์ฅ ์๋ฃ (์๊ฒฉ ๋๊ธฐํ๋ ๋ฐฑ๊ทธ๋ผ์ด๋ ์งํ ์ค)"
else:
msg = "๋ก์ปฌ ์ ์ฅ ์๋ฃ (HF_TOKEN ์์ โ ์ฌ์์ ์ ์ ์ค ๊ฐ๋ฅ)"
return f"{msg} ยท ํ์ฌ ์ฌ์ {len(dict_map)}๊ฐ{wl_note}"
# ---------- [v153] ํ์ดํธ๋ฆฌ์คํธ I/O + ๋ง์คํน ----------
def _read_local_whitelist():
try:
with open(whitelist_path, "r", encoding="utf-8") as f:
data = json.load(f)
return sorted({str(x).strip() for x in data.get("items", []) if str(x).strip()},
key=lambda x: -len(x))
except Exception:
return []
def _write_local_whitelist(wl_list):
items = sorted({s.strip() for s in wl_list if s and s.strip()}, key=lambda x: -len(x))
payload = {"items": items, "meta": {"app_title": "VoiceScript AI whitelist",
"app_version": "153.0", "count": len(items)}}
tmp_path = whitelist_path + ".tmp"
with open(tmp_path, "w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=2)
if os.path.exists(whitelist_path):
os.replace(whitelist_path, whitelist_path + ".bak")
os.replace(tmp_path, whitelist_path)
def _push_remote_whitelist():
if not hf_api:
return "๋ก์ปฌ ์ ์ฅ๋ง ๋จ (์ฌ์์ ์ ์ ์ค ๊ฐ๋ฅ - HF_TOKEN ์ค์ ํ์)"
try:
hf_api.upload_file(path_or_fileobj=whitelist_path, path_in_repo="custom_whitelist.json",
repo_id=dict_repo_id, repo_type="dataset",
commit_message="update pronunciation whitelist")
return "์๊ตฌ ์ ์ฅ ์๋ฃ"
except Exception as e:
return f"์๊ฒฉ ์ ์ฅ ์คํจ({e}) - ๋ก์ปฌ๋ง ์ ์ฅ๋จ"
def save_whitelist(wl_list):
_write_local_whitelist(wl_list)
if hf_api:
def _bg_push():
try:
msg = _push_remote_whitelist()
print(f"[ํ์ดํธ๋ฆฌ์คํธ ์๊ฒฉ ์ ์ฅ] {msg}")
except Exception as e:
print(f"[ํ์ดํธ๋ฆฌ์คํธ ์๊ฒฉ ์ ์ฅ ์คํจ] {e}")
threading.Thread(target=_bg_push, daemon=True).start()
msg = "์ ์ฅ ์๋ฃ (์๊ฒฉ ๋๊ธฐํ๋ ๋ฐฑ๊ทธ๋ผ์ด๋ ์งํ ์ค)"
else:
msg = "๋ก์ปฌ ์ ์ฅ ์๋ฃ (HF_TOKEN ์์)"
items = _read_local_whitelist()
return f"{msg} ยท ํ์ฌ ์์ธ ๋จ์ด {len(items)}๊ฐ", items
_WL_TOKEN_FMT = "\x00WL{}\x00"
def _mask_whitelist(text, wl_terms):
"""ํ์ดํธ๋ฆฌ์คํธ ๋จ์ด๋ค์ ์์ ํ ํฐ์ผ๋ก ์นํ. (masked_text, token_map) ๋ฐํ."""
if not text or not wl_terms:
return text, {}
# ๊ธด ๊ฒ๋ถํฐ ๋งค์นญ (๊ฒน์นจ ๋ฐฉ์ง)
ordered = sorted({w for w in wl_terms if w}, key=lambda x: -len(x))
token_map = {}
for idx, term in enumerate(ordered):
token = _WL_TOKEN_FMT.format(idx)
if term in text:
text = text.replace(term, token)
token_map[token] = term
return text, token_map
def _unmask_whitelist(text, token_map):
if not token_map:
return text
for token, term in token_map.items():
text = text.replace(token, term)
return text
def load_whitelist(user_temp_wl=None, user_temp_dict=None):
"""[v158] ํ์ดํธ๋ฆฌ์คํธ ์์ค:
1) custom_whitelist.json (์๊ตฌ)
2) ๊ฒ์คํธ ์์ ํ์ดํธ๋ฆฌ์คํธ (user_temp_wl)
3) ์๋ฒ ์ฌ์ + ๊ฒ์คํธ ์์ ์ฌ์ ์ ์๊ธฐ์นํ(k==v) ํญ๋ชฉ โ ๋จ, 3๊ธ์ ์ด์๋ง
('์
๋๋ค'๋ฅ ๋จ์ ์๊ธฐ์นํ์ ๋ฃ์ผ๋ฉด ์๋ฌธ ์ด๋ฏธ๊น์ง ๋ง์คํน๋์ด ์ฌ์ ๊ท์น์ด
์ ๋ถ ๋ฌด๋ ฅํ๋๋ 10/19 ๋ฒ๊ทธ์ ์ฌ๋ฐ์ ๋ง๋๋ค)
"""
base = list(_read_local_whitelist())
if user_temp_wl:
base.extend([str(x).strip() for x in user_temp_wl if str(x).strip()])
# [v158] ์์ ๋ง๋ ์๊ฒฉ ํํฐ ์ ์ฉ โ 3๊ธ์(๊ณต๋ฐฑ ์ ์ธ) ์ด์๋ง ์๋ ์์ธ๋ก ์ธ์
def _eligible(s):
return len(re.sub(r'\s+', '', s)) >= 4
try:
server_dict = _read_local_dict()
base.extend(x for x in _self_reference_keys(server_dict)
if _eligible(x) and not _wl_overlaps_rules(x, server_dict))
except Exception:
pass
if user_temp_dict:
base.extend(x for x in _self_reference_keys(user_temp_dict)
if _eligible(x) and not _wl_overlaps_rules(x, user_temp_dict))
# ์ค๋ณต ์ ๊ฑฐ + ๊ธด ์
return sorted({b.strip() for b in base if b and b.strip()}, key=lambda x: -len(x))
def perform_startup_recovery():
dict_map = _read_local_dict()
remote_ok = True
if hf_api:
try:
remote_path = hf_hub_download(repo_id=dict_repo_id, repo_type="dataset",
filename="custom_dict.json", token=HF_TOKEN)
with open(remote_path, "r", encoding="utf-8") as f:
remote = json.load(f)
for i in remote.get("items", []):
if len(i) == 2:
dict_map[i[0].strip()] = i[1].strip()
except Exception as e:
is_404 = getattr(getattr(e, "response", None), "status_code", None) == 404
if is_404:
print("[์ฌ์ ] ์๊ฒฉ์ ์์ง ์ฌ์ ํ์ผ ์์ โ ์ต์ด ๋ถํ
์ผ๋ก ์ฒ๋ฆฌ")
else:
remote_ok = False
print(f"[์ฌ์ ] ์์ธก ๋ณต์ ์คํจ({e}) - ๋ก์ปฌ ์ฌ์ ๋ณดํธ")
for w in AUTO_MERGE_WORDS:
dict_map.setdefault(w[0], w[1]) # ์ฌ์ฉ์๊ฐ ์ ๋ ์ ๋ฎ์ด์ฐ๊ธฐ
_write_local_dict(dict_map)
if hf_api and remote_ok:
_push_remote()
# [v153] ํ์ดํธ๋ฆฌ์คํธ๋ ์๊ฒฉ์์ ๋ณต์ ์๋ (์์ผ๋ฉด ๋ฌด์)
wl_local = _read_local_whitelist()
if hf_api:
try:
remote_wl_path = hf_hub_download(repo_id=dict_repo_id, repo_type="dataset",
filename="custom_whitelist.json", token=HF_TOKEN)
with open(remote_wl_path, "r", encoding="utf-8") as f:
remote_wl = json.load(f)
merged = set(wl_local) | {str(x).strip() for x in remote_wl.get("items", []) if str(x).strip()}
_write_local_whitelist(list(merged))
except Exception as e:
is_404 = getattr(getattr(e, "response", None), "status_code", None) == 404
if is_404:
print("[ํ์ดํธ๋ฆฌ์คํธ] ์๊ฒฉ์ ํ์ผ ์์ โ ์ต์ด ๋ถํ
")
else:
print(f"[ํ์ดํธ๋ฆฌ์คํธ] ์๊ฒฉ ๋ณต์ ์คํจ({e}) - ๋ก์ปฌ ๋ณดํธ")
# [v157] ๋ถํ
์ ์ฌ์ ์๊ธฐ์นํ โ ํ์ดํธ๋ฆฌ์คํธ ์๋ฐฉํฅ ๋๊ธฐํ
try:
_sync_self_refs_to_whitelist(dict_map)
except Exception as e:
print(f"[v157] ๋ถํ
ํ์ดํธ๋ฆฌ์คํธ ๋๊ธฐํ ์คํจ: {e}")
# [v158.2] ๋ถํ
์ ๊ท์น-์์ธ ์ถฉ๋ ํญ๋ชฉ ํ์ (Space ์ฌ์์ ํ์๋ ์ค์ผ ์๋ ์ ๋ฆฌ)
try:
_release_conflicting_wl_terms(dict_map)
except Exception as e:
print(f"[v158.2] ๋ถํ
ํ์ดํธ๋ฆฌ์คํธ ํ์ ์คํจ: {e}")
perform_startup_recovery()
def load_dict(user_temp_dict=None):
flat_dict = _read_local_dict()
if user_temp_dict:
flat_dict.update({k.strip(): v.strip() for k, v in user_temp_dict.items()})
return flat_dict
# ---------- 2๋จ๊ณ ๋งค์นญ ์์ง (ํ๊ธฐ ์ ๊ทํ โ ๋ฐ์ ์นํ) ----------
_ENGINE_CACHE = {"sig": None}
# [v156] ์ฌ์ ํค๋ฅผ ์๋ฌธ๊ณผ ๋งค์นญํ ๋ ์ํ ๋์์ผ๋ก ์ผ๋ ๋ฌธ์ ํด๋์ค.
# ๊ณต๋ฐฑยท๋ง์นจํยท์ผํยท๊ฐ์ด๋์ ยท๋๋ํยท๋ฌผ์ํยท์ค์ ยท๋ง์ค์ โ ๋ชจ๋ '์์ด๋/์์ด๋' ๋งค์นญ.
_PUNCT_FLEX = r'[\s,\.\!\?ยทโขโฆใใ]*'
def _flex_body_pure_hangul(k):
"""[v156] ์์ ํ๊ธ ํค์ ๋ํด '๊ณต๋ฐฑ/๊ตฌ๋์ ์ ์ฐ' ์ ๊ท์ ๋ชธํต ์์ฑ.
- ํค ๋ด๋ถ์ ๊ณต๋ฐฑยท๊ตฌ๋์ ์ ์๋ฌธ์์ ์์ด๋ ์์ด๋ ๋งค์นญ๋๋๋ก [\\s,.!?...]* ๋ก ์นํ
- ํ๊ธ ์ฌ์ด์๋ ์๋ฌธ ๊ตฌ๋์ (์: ', ')์ด ๋ผ์ด๋ ๋งค์นญ๋๋๋ก [\\s,.!?...]* ๋ฅผ ์ฝ์
์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉ์๊ฐ ๋ง์นจํยท์ผํยท๋์ด์ฐ๊ธฐ๋ฅผ ์ด๋ป๊ฒ ๋ฃ๋ ๋งค์นญ๋จ.
"""
# ํค์์ ๊ณต๋ฐฑยท๊ตฌ๋์ ์ ๋ชจ๋ ๋ฝ์๋ธ ํ๊ธ ์ํ์ค
hangul_only = re.sub(r'[\s,\.\!\?ยทโขโฆใใ]+', '', k)
if not hangul_only:
# ํ๊ธ์ด ์์ผ๋ฉด (์ด ํจ์๊ฐ ํธ์ถ๋ ๋ฆฌ ์์ง๋ง) ๊ธฐ์กด ๋ฐฉ์ ์ ์ง
return r'\s*'.join(map(re.escape, k.split(" ")))
# ํ ๊ธ์๋ง๋ค ๋ค์ ์ ์ฐ ๊ตฌ๋์ ํด๋์ค ์ฝ์
(๋ง์ง๋ง ๊ธ์ ๋ค์ ๋ถ์ด์ง ์์)
parts = []
for i, ch in enumerate(hangul_only):
parts.append(re.escape(ch))
if i < len(hangul_only) - 1:
parts.append(_PUNCT_FLEX)
return "".join(parts)
def _build_pattern(keys):
r"""ํค ๊ธธ์ด ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ ํ ๊ณต๋ฐฑ์ \s* ๋ก ๋ฐ๊พผ ์ ์ฐ ํจํด. ๊ทธ๋ฃน๋ฒํธโํค.
[v150] 1๊ธ์ ์์ซ์ ํค๋ ๋จ์ด ๊ฒฝ๊ณ(boundary)๋ฅผ ๊ฐ์ ํด์
'CLASS' ๊ฐ์ ๋จ์ด ์ค๊ฐ์์ ์คํ๋์ง ์๊ฒ ํ๋ค.
[v152] ์์ ํ๊ธ ํค๋ ์ข์ธก์ ํ๊ธ์ด ์ค๋ฉด ๋งค์นญ ๊ธ์ง โ '์์ค'๊ฐ
'ํด๋ฆฌ์์คํฐ' ๊ฐ์ ํฉ์ฑ์ด ์ค๊ฐ์์ ์คํ๋์ง ์๋๋ก.
[v154] ์์ ํ๊ธ ํค๋ guarded=True โ ์ค์ ๋งค์นญ ์ ํํ์ ๊ฒฝ๊ณ
(์กฐ์ฌ/์ด๋ฏธ ์ฌ๋ถ, Kiwi ๋๋ ์กฐ์ฌ ๋ฆฌ์คํธ ํด๋ฐฑ)๋ฅผ ํ์ธํด
'์์ค์ปฌ๋ ์ดํฐ/์์คํ๋ ์/์ ์ด์จ์ฐ' ๊ฐ์ ํฉ์ฑ์ด ์คํ์ ๋ง๋๋ค.
[v156] ์์ ํ๊ธ ํค(๊ณต๋ฐฑยท๊ตฌ๋์ ์์ฌ ์์ด๋ ํ๊ธ๋ง ๋จ์ผ๋ฉด ์์ ํ๊ธ๋ก ์ทจ๊ธ)๋
์๋ฌธ์ ๊ณต๋ฐฑยท๊ตฌ๋์ ํธ์ฐจ๋ฅผ ํก์ํ๋๋ก ์ ์ฐ ๋งค์นญ ๋ชธํต์ ์ฌ์ฉํ๋ค."""
ordered = sorted(keys, key=lambda x: -len(x.replace(" ", "")))
if not ordered:
return None, [], []
pats, guarded = [], []
for k in ordered:
if len(k) == 1 and re.match(r'^[A-Za-z0-9_]$', k):
# 1๊ธ์ ์์ซ์: ์ข์ฐ alphanumeric/underscore๊ฐ ์ค๋ฉด ๋งค์นญ ์ ํจ
pats.append(rf'(?<![A-Za-z0-9_]){re.escape(k)}(?![A-Za-z0-9_])')
guarded.append(False)
else:
# [v156] ๊ณต๋ฐฑยท๊ตฌ๋์ ์ ์ ๊ฑฐํ์ ๋ ์์ ํ๊ธ์ด๋ฉด ์ ์ฐ ๋งค์นญ ๋ชธํต ์ฌ์ฉ
stripped = re.sub(r'[\s,\.\!\?ยทโขโฆใใ]+', '', k)
if stripped and re.match(r'^[๊ฐ-ํฃ]+$', stripped):
body = _flex_body_pure_hangul(k)
pats.append(rf'(?<![๊ฐ-ํฃ]){body}')
guarded.append(True)
else:
body = r'\s*'.join(map(re.escape, k.split(" ")))
pats.append(body)
guarded.append(False)
return re.compile("|".join(f"({p})" for p in pats)), ordered, guarded
def get_engine(flat_dict):
sig = hash(tuple(sorted(flat_dict.items())))
if _ENGINE_CACHE.get("sig") == sig:
return _ENGINE_CACHE
phase1, phase2, shields = {}, {}, set()
for k, v in flat_dict.items():
if not k:
continue
if k == v:
shields.add(k)
elif re.sub(r'[\s,\.\!\?ยทโขโฆใใ]+', '', k) == re.sub(r'[\s,\.\!\?ยทโขโฆใใ]+', '', v):
phase1[k] = v
shields.add(v)
else:
phase2[k] = v
p1_pat, p1_keys, p1_guard = _build_pattern(phase1.keys())
p2_pat, p2_keys, p2_guard = _build_pattern(phase2.keys())
sh_pat, _, _ = _build_pattern(shields)
_ENGINE_CACHE.update({"sig": sig, "phase1": phase1, "phase2": phase2,
"p1_pat": p1_pat, "p1_keys": p1_keys,
"p2_pat": p2_pat, "p2_keys": p2_keys, "sh_pat": sh_pat,
"p1_guard": p1_guard, "p2_guard": p2_guard})
return _ENGINE_CACHE
def _sub_phase1(text, eng, boundary=None):
if not eng["p1_pat"]:
return text
guard = eng.get("p1_guard", []) or []
def _repl(m):
gi = m.lastindex - 1
if guard[gi] and boundary is not None and not boundary.allow_after(m.end()):
return m.group() # ํฉ์ฑ์ด ๋ด๋ถ โ ์ ์ง
return eng["phase1"][eng["p1_keys"][gi]]
return eng["p1_pat"].sub(_repl, text)
def _segments_phase2(text, eng, boundary=None):
if not eng["p2_pat"] or not text:
return [(False, text)] if text else []
guard = eng.get("p2_guard", []) or []
segs, last = [], 0
for m in eng["p2_pat"].finditer(text):
s, e = m.span()
gi = m.lastindex - 1
if guard[gi] and boundary is not None and not boundary.allow_after(e):
continue # ํฉ์ฑ์ด ๋ด๋ถ โ ์ด ๋งค์นญ ๊ฑด๋๋ (์๋ฌธ ์ ์ง)
if s > last:
segs.append((False, text[last:s]))
segs.append((True, eng["phase2"][eng["p2_keys"][gi]]))
last = e
if last < len(text):
segs.append((False, text[last:]))
return segs
def _g2p_shielded(chunk, mode, eng):
if not chunk:
return chunk
if not eng["sh_pat"]:
return apply_g2p(chunk, mode)
res, last = [], 0
for m in eng["sh_pat"].finditer(chunk):
s, e = m.span()
if s > last:
res.append(apply_g2p(chunk[last:s], mode))
res.append(m.group())
last = e
res.append(apply_g2p(chunk[last:], mode))
return "".join(res)
def convert_text(text, mode, flat_dict, whitelist=None):
"""์๋ฌธ ๋น๊ณต๋ฐฑ ๋ฌธ์์ด ๋ณํ ์ ํ ๋์ผ์ฑ ์ ์ง.
์ธํ ๋ณํ๋ ์ฌ์ ยท์ซ์ยท๋ฌธ์ฅ๋ถํธ ํธํก ๋ง์ปค๋ก๋ง ๋ง๋ค์ด์ง๋ค.
[v153] whitelist์ ํฌํจ๋ ๋จ์ด๋ ์ด๋ค ์ฌ์ ํค๊ฐ ์์ ๋ค์ด์์ด๋
์นํ ๋์์์ ์์ ํ ์ ์ธ๋๋ค."""
text, wl_map = _mask_whitelist(text, whitelist or [])
eng = get_engine(flat_dict)
t = _sub_phase1(text, eng, _MorphBoundary(text))
out = []
b2 = _MorphBoundary(t)
for fixed, chunk in _segments_phase2(t, eng, b2):
if fixed:
out.append(chunk)
continue
chunk = apply_smart_regex(chunk)
# [v154] 2์ฐจ ๋งค์นญ๋ ์กฐ๊ฐ ๋จ์ ํํ์ ๊ฐ๋ ์ ์ฉ โ 1์ฐจ์์ ๊ฑฐ์ ๋
# ํฉ์ฑ์ด(์์ค์ปฌ๋ ์ดํฐ ๋ฑ)๊ฐ ์ด ๋ฃจํ์์ ์ฌ์คํ๋๋ ๊ฒ ๋ฐฉ์ง.
b_chunk = _MorphBoundary(chunk)
for fixed2, c2 in _segments_phase2(chunk, eng, b_chunk):
out.append(c2 if fixed2 else _g2p_shielded(c2, mode, eng))
return _unmask_whitelist("".join(out), wl_map)
# ---------- G2P ๋ชจ๋ ----------
def apply_g2p(text, mode):
if g2p is None or mode.startswith("๋๊ธฐ"):
return text
if mode.startswith("๋งค์ด ๋ง"):
try:
return g2p(text)
except Exception:
return text
if mode.startswith("์ํ ๋ง"):
words = re.split(r'(\s+)', text)
res = []
for w in words:
if w.strip():
try:
res.append(g2p(w))
except Exception:
res.append(w)
else:
res.append(w)
return "".join(res)
if mode.startswith("์ค๊ฐ ๋ง"):
# ๋ช
์ฌ/๊ณ ์ ์ด (ํ๊ธ 2๊ธ์+) ๋ง ๋ณํ, ๋จ์ผ ์กฐ์ฌยท๋ณด์กฐ์ฌยท๊ธฐํธ๋ ๊ฑด๋๋
tokens = re.split(r'([๊ฐ-ํฃ]+|[a-zA-Z]+|\d+|[^\w\s]+|\s+)', text)
particles = {'์ด', '๊ฐ', '์', '๋ฅผ', '์', '๋', '์', '๋ก', '์ผ๋ก', '๊ณ ',
'๋ค', '์ด', '์', '๋ค', '์
๋๋ค', '์ต๋๋ค'}
res = []
for t in tokens:
if not t:
continue
if t.isspace() or t in particles or len(t) == 1:
res.append(t)
elif re.match(r'^[๊ฐ-ํฃ]{2,}$', t):
try:
res.append(g2p(t))
except Exception:
res.append(t)
else:
res.append(t)
return "".join(res)
return text
# ---------- ์ซ์/๋จ์ ํ๊ตญ์ด ๋ณํ ----------
def number_to_korean(num_str):
num_str = num_str.replace(',', '')
try:
n = int(num_str)
except Exception:
return num_str
if n == 0:
return "์"
digits, units, large_units = ["", "์ผ", "์ด", "์ผ", "์ฌ", "์ค", "์ก", "์น ", "ํ", "๊ตฌ"], \
["", "์ญ", "๋ฐฑ", "์ฒ"], ["", "๋ง", "์ต", "์กฐ"]
res, str_n = [], str(n)[::-1]
for i in range(0, len(str_n), 4):
chunk, chunk_res = str_n[i:i+4], []
for j, char in enumerate(chunk):
d = int(char)
if d > 0:
word = digits[d] if d > 1 or j == 0 else ""
if d == 1 and j == 0 and len(chunk) == 1 and i == 0:
word = "์ผ"
chunk_res.append(word + units[j])
if chunk_res:
res.append("".join(chunk_res[::-1]) + large_units[i//4])
return "".join(res[::-1]) or num_str
def apply_smart_regex(text):
if not text:
return text
text = re.sub(r'\b1\s*๋ง\s*์\s*๋\b', "๋ง์๋", text)
text = re.sub(r'\b1\s*๋ง์\s*๋\b', "๋ง์๋", text)
text = re.sub(r'\b1\s*๋ง์๋\b', "๋ง์๋", text)
text = re.sub(r'(\d+)\s*๊ฐ์\b', lambda m: f"{number_to_korean(m.group(1))}๊ฐ์", text)
text = re.sub(r'(\d+)\s*(%|ํ๋ก)\b', lambda m: f"{number_to_korean(m.group(1))}ํ๋ก", text)
size_dict = {"55": "์ค์ค", "66": "์ต์ก", "77": "์น ์น ", "88": "ํํ",
"95": "๊ตฌ์ค", "100": "๋ฐฑ", "105": "๋ฐฑ์ค", "110": "๋ฐฑ์ญ"}
def _size_repl(m):
k = m.group(1)
return f"{size_dict[k]} ์ธ์ด์ฆ" if k in size_dict else m.group(0)
text = re.sub(r'\b(55|66|77|88|95|100|105|110)\s*์ฌ์ด์ฆ\b', _size_repl, text)
text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*๋ง\s*์\s*๋\b',
lambda m: f"{number_to_korean(m.group(1))}๋ง์๋", text)
text = re.sub(r'(\d{1,3}(?:,\d{3})+|\d+)\s*์\b',
lambda m: f"{number_to_korean(m.group(1))} ์", text)
unit_dict = {"mm": "๋ฐ๋ฆฌ๋ฏธํฐ", "cm": "์ผํฐ๋ฏธํฐ", "m": "๋ฏธํฐ", "km": "ํฌ๋ก๋ฏธํฐ",
"g": "๊ทธ๋จ", "kg": "ํฌ๋ก๊ทธ๋จ", "ml": "๋ฐ๋ฆฌ๋ฆฌํฐ", "L": "๋ฆฌํฐ"}
def _unit_repl(m):
num_u, u = m.group(1), m.group(2).lower() if m.group(2).lower() != 'l' else 'L'
return f"{number_to_korean(num_u)} {unit_dict[u]}"
text = re.sub(r'(\d+)\s*(mm|cm|m|km|g|kg|ml|L)\b', _unit_repl, text, flags=re.IGNORECASE)
return text
# ---------- ์ฒ๋ฆฌ ํ ์ค์ ๋ชจ์ผ๊ธฐ (ํธํก์ ๋ง ๋ฌธ์ฅ๋ถํธ ๊ธฐ๋ฐ) ----------
def _join_breath_marks(text):
"""์ผํยท๊ฐ์ด๋์ ยท๋ง์ค์ํ ๋ค์ ํธํก ๋งํฌ('/')๋ฅผ ๋ฃ๊ณ , `@@` ๋ง์ปค๋ ๋ณด์กดํ๋ค."""
text = re.sub(r'[,ใ]\s*', ', / ', text)
text = re.sub(r'[ยทโข]\s*', 'ยท / ', text)
text = re.sub(r'โฆ\s*', 'โฆ / ', text)
return text
def process_text(input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl=None):
if not input_text or not input_text.strip():
return "", f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:{font_size}px;"></div>', \
"๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
char_count = f"๊ณต๋ฐฑ ํฌํจ: {len(input_text)}์ / ๊ณต๋ฐฑ ์ ์ธ: {len(input_text.replace(' ', '').replace(chr(10), ''))}์"
flat_dict = load_dict(user_temp_dict)
whitelist = load_whitelist(user_temp_wl, user_temp_dict)
if not flat_dict:
# ์ฌ์ ์ ์๋๋ผ๋ ํ์ดํธ๋ฆฌ์คํธ๋ ์ค๋งํธ ์ ๊ท์/G2P์์ ๋ณดํธ๋์ด์ผ ํจ
masked, wl_map = _mask_whitelist(input_text, whitelist)
final_text = _unmask_whitelist(apply_g2p(apply_smart_regex(masked), ai_mode), wl_map)
else:
final_text = convert_text(input_text, ai_mode, flat_dict, whitelist)
if smart_pause:
final_text = _join_breath_marks(final_text)
if auto_break:
final_text = final_text.replace(". ", ".\n\n").replace("? ", "?\n\n").replace("! ", "!\n\n")
seq = difflib.SequenceMatcher(None, input_text, final_text)
html_parts = []
for tag, i1, i2, j1, j2 in seq.get_opcodes():
chunk = html.escape(final_text[j1:j2]).replace('\n', '<br>')
if tag == 'equal':
html_parts.append(chunk)
elif tag in ['replace', 'insert']:
html_parts.append(f'<span style="background-color: #ffe066; font-weight: bold;">{chunk}</span>')
raw_html = re.sub(r'([^\s<]*@@[^\s<]*)', r'<span style="background-color: #ff4d4d; color: white;">\1</span>', "".join(html_parts))
html_output = f'<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:{font_size}px;">{raw_html}</div>'
markers = re.findall(r'[^\s]*@@[^\s]*', input_text)
unique_markers = list(dict.fromkeys([m.strip('.,!?\n') for m in markers if m.strip('.,!?\n')]))
return final_text, html_output, char_count, " / ".join(unique_markers) if unique_markers else "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def clear_all():
return "", "", '<div id="prompter_output_div" style="font-size:22px;"></div>', "๊ณต๋ฐฑ ํฌํจ: 0์ / ๊ณต๋ฐฑ ์ ์ธ: 0์", "ํ์๋ ๋ง์ปค(@@)๊ฐ ์์ต๋๋ค."
def get_file():
return dict_path if os.path.exists(dict_path) else None
def add_and_update(word, pronun, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl=None):
if not word or not pronun:
return "โ ๏ธ ๋จ์ด์ ๋ฐ์์ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict
word, pronun = word.strip(), pronun.strip()
# [v150] 1๊ธ์ ํค ํ์ฉ โ ๊ฒฝ๊ณ๋ _build_pattern์์ ์ฒ๋ฆฌ
# [v158] ๋ฐ์ ์คํ ๊ฐ์ง โ ๋ฌธ์ ๊ฐ ์์ผ๋ฉด ์ ์ฅํ์ง ์๊ณ ๋๋ฌผ์
typos = _detect_pronun_typo(word, pronun)
if typos:
status_msg = "๐ ๋ฑ๋ก ๋ณด๋ฅ: " + " / ".join(typos) + " โ ๋ฐ์์ ํ์ธ ํ ๋ค์ ๋ฑ๋กํ์ธ์."
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, user_temp_dict
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict
if user_role == "admin":
dict_map = _read_local_dict()
# [v158-final] ๊ฒน์น๋ ๊ธฐ์กด ๊ท์น์ '๊ฐ์ง๋ง' ํ๋ค โ ์ ๋ ์ญ์ ํ์ง ์์.
# ์์ง์ด ๊ธด ํค ์ฐ์ ๋งค์นญ์ด๋ผ ์ฐ์ ์์๋ ๋ณด์ฅ๋๋ฉฐ, ๊ธฐ์กด ๋จ์ด์ฅ์ ์จ์ ํ ๋ณด์กด๋๋ค.
overlapping = _find_overlapping_keys(dict_map, word)
dict_map[word] = pronun
sync_msg = save_dict(dict_map)
if overlapping:
new_len = len(re.sub(r'\s+', '', word))
longer = [k for k in overlapping if len(re.sub(r'\s+', '', k)) > new_len]
if longer:
prune_note = f" ยท โ ๏ธ ๊ธฐ์กด ๊ธด ๊ท์น '{longer[0]}'๊ฐ ์ด ํค๋ณด๋ค ์ฐ์ ์ ์ฉ๋ ์ ์์ (๊ฒน์น๋ ๊ตฌ๊ฐ ์ฃผ์)"
else:
prune_note = f" ยท ์ ์ฌ ๊ธฐ์กด ๊ท์น {len(overlapping)}๊ฐ ์กด์ฌ (์ ๊ท์น์ด ์ฐ์ ์ ์ฉ๋จ)"
else:
prune_note = ""
status_msg = f"๐ [์ด๋๋ฏผ] '{word}' -> '{pronun}' ์ ์ฅ!{prune_note} ({sync_msg})"
else:
# [v158-final] ๊ฒ์คํธ ์์ ์ฌ์ ๋ ๋์ผ โ ์ญ์ ์์ด ๊ฐ์ง๋ง
overlapping = [k for k in user_temp_dict.keys()
if k != word and len(re.sub(r'\s+', '', k)) >= 4
and (re.sub(r'\s+', '', k).startswith(re.sub(r'\s+', '', word))
or re.sub(r'\s+', '', word).startswith(re.sub(r'\s+', '', k)))]
user_temp_dict[word] = pronun
prune_note = f" ยท ์ ์ฌ ๊ธฐ์กด ๊ท์น {len(overlapping)}๊ฐ ์กด์ฌ (๊ธด ํค ์ฐ์ ์ ์ฉ)" if overlapping else ""
status_msg = f"๐ค [๊ฒ์คํธ] '{word}' -> '{pronun}' ์์ ์ ์ฅ ์๋ฃ!{prune_note} (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ - ์๊ตฌ ๋ฑ๋ก์ ์ด๋๋ฏผ์๊ฒ ์์ฒญ)"
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, user_temp_dict
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), user_temp_dict
def load_current_json_to_text(user_temp_dict):
try:
return json.dumps({"items": load_dict(user_temp_dict)}, ensure_ascii=False, indent=4), "โ
์ฌ์ ์ ๋ถ๋ฌ์์ต๋๋ค!"
except Exception as e:
return "", f"โ ์คํจ: {e}"
def _parse_items(json_string):
new_data = json.loads(json_string)
items = new_data.get("items", [])
if isinstance(items, dict):
return {k.strip(): str(v).strip() for k, v in items.items()}
return {i[0].strip(): i[1].strip() for i in items if len(i) == 2}
def overwrite_json_text(json_string, user_role):
if user_role != "admin":
return "๐ซ [๊ถํ ์์] ์ด๋๋ฏผ๋ง ๋ฎ์ด์ฐ๊ธฐ๊ฐ ๊ฐ๋ฅํฉ๋๋ค."
if not json_string.strip():
return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์."
try:
dict_map = _parse_items(json_string)
sync_msg = save_dict(dict_map)
return f"๐ [์ด๋๋ฏผ] ์๋ฒ ์ฌ์ ์ ์์ ํ ๊ต์ฒดํ์ต๋๋ค! ({sync_msg})"
except Exception as e:
return f"โ ์๋ฌ: {e}"
def apply_json_text(json_string, user_role, user_temp_dict):
if not json_string.strip():
return "โ ๏ธ ๋ด์ฉ์ ์
๋ ฅํด์ฃผ์ธ์.", user_temp_dict
try:
parsed_items = _parse_items(json_string)
if user_role == "admin":
dict_map = _read_local_dict()
dict_map.update(parsed_items)
sync_msg = save_dict(dict_map)
return f"๐ [์ด๋๋ฏผ] ์๋ฒ์ ์ถ๊ฐํ์ต๋๋ค! ({sync_msg})", user_temp_dict
else:
user_temp_dict.update(parsed_items)
return "๐ค [๊ฒ์คํธ] ์์ ๋จ์ด์ฅ์ ์ถ๊ฐ๋์์ต๋๋ค!", user_temp_dict
except Exception as e:
return f"โ ์๋ฌ: {e}", user_temp_dict
def update_dict_entry(old_word, new_pronun, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl=None):
"""๋จ์ด์ฅ ํญ๋ชฉ ์์ โ key(๋จ์ด) ์๋ณ์๊ฐ ๊ทธ๋๋ก์ธ ๋์ value(๋ฐ์)๋ง ๊ต์ฒด."""
if not old_word:
return "โ ๏ธ ๋จผ์ ๋จ์ด๋ฅผ ์ ํํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_word = old_word.strip()
new_pronun = (new_pronun or "").strip()
if not new_pronun:
return "โ ๏ธ ์ ๋ฐ์์ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
if user_role == "admin":
dict_map = _read_local_dict()
if old_word not in dict_map:
return f"๐ซ ๋จ์ด์ฅ์ '{old_word}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_value = dict_map[old_word]
dict_map[old_word] = new_pronun
sync_msg = save_dict(dict_map)
status_msg = f"๐ [์์ ] '{old_word}' : '{old_value}' โ '{new_pronun}' ({sync_msg})"
else:
if old_word not in user_temp_dict:
return f"๐ซ ์์ ๋จ์ด์ฅ์ '{old_word}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_value = user_temp_dict[old_word]
user_temp_dict[old_word] = new_pronun
status_msg = f"๐ค [๊ฒ์คํธ ์์ ] '{old_word}' : '{old_value}' โ '{new_pronun}' (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, update_choices(), user_temp_dict
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
def delete_dict_entry(old_word, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl=None):
"""๋จ์ด์ฅ ํญ๋ชฉ์์ ํ ์ค๋ง ์ญ์ . ADMIN_IDยท์ด๋๋ฏผ์ด๋ฉด ์๋ฒ ์ ์ฅ์, ๊ฒ์คํธ๋ฉด ์์ ์ฌ์ ."""
if not old_word:
return "โ ๏ธ ๋จผ์ ๋จ์ด๋ฅผ ์ ํํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_word = old_word.strip()
if user_role == "admin":
dict_map = _read_local_dict()
if old_word not in dict_map:
return f"๐ซ ๋จ์ด์ฅ์ '{old_word}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_value = dict_map.pop(old_word)
sync_msg = save_dict(dict_map)
status_msg = f"๐๏ธ [์ญ์ ] '{old_word}' : '{old_value}' ({sync_msg})"
else:
if old_word not in user_temp_dict:
return f"๐ซ ์์ ๋จ์ด์ฅ์ '{old_word}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
old_value = user_temp_dict.pop(old_word)
status_msg = f"๐๏ธ [๊ฒ์คํธ ์ญ์ ] '{old_word}' : '{old_value}' (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, update_choices(), user_temp_dict
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), update_choices(), user_temp_dict
# ---------- [v153] ํ์ดํธ๋ฆฌ์คํธ UI ํธ๋ค๋ฌ ----------
def add_whitelist_entry(term, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl):
term = (term or "").strip()
if not term:
return "โ ๏ธ ์์ธ ๋จ์ด๋ฅผ ์
๋ ฅํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), user_temp_wl
if user_role == "admin":
wl = _read_local_whitelist()
if term in wl:
status_msg = f"โน๏ธ ์ด๋ฏธ ์์ธ ๋ชฉ๋ก์ ์์: '{term}'"
else:
wl.append(term)
msg, _ = save_whitelist(wl)
status_msg = f"๐ [์ด๋๋ฏผ] ์์ธ ๋จ์ด ์ถ๊ฐ: '{term}' ({msg})"
else:
if term in user_temp_wl:
status_msg = f"โน๏ธ ์ด๋ฏธ ์์ ์์ธ ๋ชฉ๋ก์ ์์: '{term}'"
else:
user_temp_wl.append(term)
status_msg = f"๐ค [๊ฒ์คํธ] ์์ ์์ธ ์ถ๊ฐ: '{term}' (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"
dd_update = gr.update(choices=list(_read_local_whitelist()))
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, dd_update, user_temp_wl
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), dd_update, user_temp_wl
def delete_whitelist_entry(term, user_role, current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl):
term = (term or "").strip()
if not term:
return "โ ๏ธ ์ญ์ ํ ์์ธ ๋จ์ด๋ฅผ ์ ํํ์ธ์.", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), user_temp_wl
if user_role == "admin":
wl = _read_local_whitelist()
if term not in wl:
return f"๐ซ ์์ธ ๋ชฉ๋ก์ '{term}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), user_temp_wl
wl = [x for x in wl if x != term]
msg, _ = save_whitelist(wl)
status_msg = f"๐๏ธ [์์ธ ์ญ์ ] '{term}' ({msg})"
else:
if term not in user_temp_wl:
return f"๐ซ ์์ ์์ธ ๋ชฉ๋ก์ '{term}' ๊ฐ ์์ต๋๋ค.", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), user_temp_wl
user_temp_wl = [x for x in user_temp_wl if x != term]
status_msg = f"๐๏ธ [๊ฒ์คํธ ์์ธ ์ญ์ ] '{term}' (์๋ก๊ณ ์นจ ์ ์ด๊ธฐํ)"
dd_update = gr.update(choices=list(_read_local_whitelist()), value=None)
if current_input.strip():
ft, ho, cc, mr = process_text(current_input, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl)
return status_msg, ft, ho, cc, mr, dd_update, user_temp_wl
return status_msg, gr.update(), gr.update(), gr.update(), gr.update(), dd_update, user_temp_wl
def refresh_whitelist_choices():
return gr.update(choices=list(_read_local_whitelist()))
def update_choices():
"""๋๋กญ๋ค์ด์ ํ์ฌ ์๋ฒ ์ฌ์ ์ ํค๋ค์ ์ํ๋ฒณ์์ผ๋ก ๋
ธ์ถ."""
d = _read_local_dict()
return gr.update(choices=sorted(d.keys()))
def upload_file(file_path, user_role, user_temp_dict):
if file_path is None:
return "โ ๏ธ ํ์ผ์ด ์์ต๋๋ค.", user_temp_dict
try:
with open(file_path, "r", encoding="utf-8") as f:
uploaded_data = json.load(f)
parsed_items = {item[0].strip(): item[1].strip() for item in uploaded_data.get("items", []) if len(item) == 2}
if user_role == "admin":
dict_map = _read_local_dict()
dict_map.update(parsed_items)
sync_msg = save_dict(dict_map)
return f"๐ [์ด๋๋ฏผ] ํ์ผ ๋ฐ์ดํฐ๋ฅผ ์๋ฒ์ ๋ณํฉํ์ต๋๋ค! ({sync_msg})", user_temp_dict
else:
user_temp_dict.update(parsed_items)
return "๐ค [๊ฒ์คํธ] ๋ด ์์ ๋จ์ด์ฅ์ ๋ณํฉ๋์์ต๋๋ค!", user_temp_dict
except Exception as e:
return f"โ ์๋ฌ: {e}", user_temp_dict
def verify_login(uid, upw):
if uid == ADMIN_ID and upw == ADMIN_PW:
return gr.update(visible=False), gr.update(visible=True), "admin", "โ
๋ก๊ทธ์ธ ์ฑ๊ณต (์ด๋๋ฏผ ๋ชจ๋)", ""
elif uid == GUEST_ID and upw == GUEST_PW:
return gr.update(visible=False), gr.update(visible=True), "guest", "โ
๋ก๊ทธ์ธ ์ฑ๊ณต (๊ฒ์คํธ ๋ชจ๋)", ""
else:
return gr.update(visible=True), gr.update(visible=False), "none", "โ ์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ต๋๋ค.", ""
def perform_logout():
return gr.update(visible=True), gr.update(visible=False), "none", "", "", "", {}, []
def handle_page_load(current_role):
if current_role in ["admin", "guest"]:
return gr.update(visible=False), gr.update(visible=True), current_role, "", gr.update(), gr.update()
return gr.update(visible=True), gr.update(visible=False), "none", "", "", ""
# ---------- UI ๋น๋ ----------
custom_css = """
#prompter_html_wrap, #prompter_html_wrap .prose { width: 100% !important; text-align: left !important; }
#input_text_area textarea, #output_text_area textarea, #prompter_output_div {
font-family: sans-serif !important; height: 500px !important;
overflow-y: auto !important; padding: 16px !important; line-height: 1.8 !important;
}
#prompter_output_div { background-color: #333 !important; color: #fff !important; border-radius: 8px !important; white-space: pre-wrap !important; }
.login-box { max-width: 400px; margin: 100px auto; padding: 30px; border: 1px solid #ddd; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
/* ๋ฒํผ ํ 4๊ฐ ๋์ผ ํญ (Gradio use_container_width ๋์ CSS ๋ณด๊ฐ) */
.convert-row { gap: 8px !important; }
.convert-row > button { flex: 1 1 0 !important; min-width: 0 !important; }
"""
script_js = """
function() {
setTimeout(function() {
let ta1 = document.querySelector('#input_text_area textarea');
if(ta1) { ta1.style.fontSize = '22px'; }
let ta2 = document.querySelector('#output_text_area textarea');
if(ta2) { ta2.style.fontSize = '22px'; ta2.style.lineHeight = '1.8'; }
}, 500);
let isSyncing1 = false; let isSyncing2 = false; let isSyncing3 = false;
document.addEventListener('scroll', function(e) {
let target = e.target;
let ta1 = document.querySelector('#input_text_area textarea');
let ta2 = document.querySelector('#output_text_area textarea');
let div3 = document.getElementById('prompter_output_div');
if (!ta1 || !div3) return;
if (target === ta1) {
if (isSyncing1) { isSyncing1 = false; return; }
if (ta1.scrollHeight - ta1.clientHeight <= 0) return;
isSyncing2 = true; isSyncing3 = true;
let percentage = ta1.scrollTop / (ta1.scrollHeight - ta1.clientHeight);
if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); }
if (div3.scrollHeight - div3.clientHeight > 0) { div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); }
} else if (target === ta2) {
if (isSyncing2) { isSyncing2 = false; return; }
if (ta2 && ta2.scrollHeight - ta2.clientHeight <= 0) return;
isSyncing1 = true; isSyncing3 = true;
let percentage = ta2.scrollTop / (ta2.scrollHeight - ta2.clientHeight);
if (ta1.scrollHeight - ta1.clientHeight > 0) { ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); }
if (div3.scrollHeight - div3.clientHeight > 0) { div3.scrollTop = percentage * (div3.scrollHeight - div3.clientHeight); }
} else if (target === div3) {
if (isSyncing3) { isSyncing3 = false; return; }
if (div3.scrollHeight - div3.clientHeight <= 0) return;
isSyncing1 = true; isSyncing2 = true;
let percentage = div3.scrollTop / (div3.scrollHeight - div3.clientHeight);
if (ta1.scrollHeight - ta1.clientHeight > 0) { ta1.scrollTop = percentage * (ta1.scrollHeight - ta1.clientHeight); }
if (ta2 && ta2.scrollHeight - ta2.clientHeight > 0) { ta2.scrollTop = percentage * (ta2.scrollHeight - ta2.clientHeight); }
}
}, true);
}
"""
insert_marker_js = "(t) => { let ta = document.querySelector('#input_text_area textarea'); if (!ta) return t; let s = ta.selectionStart, e = ta.selectionEnd, v = ta.value; ta.value = v.substring(0, s) + '@@' + v.substring(e); ta.dispatchEvent(new Event('input', { bubbles: true })); ta.selectionStart = ta.selectionEnd = s + 2; ta.focus(); return ta.value; }"
_mode_choices = ["๋๊ธฐ (์๋ ์ฌ์ ๋ง ์ ์ฉ)", "์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)",
"์ํ ๋ง (๋จ์ด๋ณ ๋๊ธฐ)", "๋งค์ด ๋ง (์์ฐ ์ฐ์)"]
_GRADIO_MAJOR = int(gr.__version__.split(".")[0])
_BLOCKS_KW = {"theme": "default", "css": custom_css} if _GRADIO_MAJOR < 6 else {}
_LAUNCH_KW = {"theme": "default", "css": custom_css} if _GRADIO_MAJOR >= 6 else {}
with gr.Blocks(**_BLOCKS_KW) as iface:
user_role = gr.State("none")
user_temp_dict = gr.State(lambda: {})
user_temp_wl = gr.State(lambda: []) # [v153] ๊ฒ์คํธ ์์ ํ์ดํธ๋ฆฌ์คํธ
with gr.Column(visible=True, elem_classes="login-box") as login_screen:
gr.Markdown("### ๐ ์์คํ
๋ก๊ทธ์ธ")
login_id = gr.Textbox(label="์์ด๋")
login_pw = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password")
login_btn = gr.Button("๋ก๊ทธ์ธ", variant="primary")
login_msg = gr.Markdown("")
with gr.Column(visible=False) as main_app:
with gr.Row(elem_classes="header-row"):
gr.Markdown("## ๐๏ธ AI ์คํฌ๋ฆฝํฐ ๋ณํ๊ธฐ")
btn_logout = gr.Button("๐ช ๋ก๊ทธ์์", variant="secondary", size="sm", scale=0, min_width=100)
with gr.Tabs():
with gr.Tab("๐๏ธ ๋ฉ์ธ ํ๋ฉด"):
with gr.Row():
with gr.Column():
input_text = gr.Textbox(label="1๏ธโฃ ์๋ณธ ํ
์คํธ ์
๋ ฅ", elem_id="input_text_area")
with gr.Group():
ai_mode = gr.Radio(choices=_mode_choices,
value="์ค๊ฐ ๋ง (๋ช
์ฌ/๊ณ ์ ์ด๋ง - ์ถ์ฒ โญ)",
label="๐ค AI ๋ฐ์ ๋ณํ ๊ฐ๋")
auto_break = gr.Checkbox(label="๐ ๋ฌธ์ฅ ๋ ์๋ ์ค๋ฐ๊ฟ", value=False)
smart_pause = gr.Checkbox(label="โฑ๏ธ ์ผํ ๋ค ํธํก์ ( / ) ์ถ๊ฐ", value=False)
btn_insert_marker = gr.Button("๐จ ๋ง์ปค(@@) ์ฝ์
", variant="secondary", size="sm")
font_size = gr.Slider(minimum=16, maximum=40, value=22, step=2, label="๐ ๊ธ์ ํฌ๊ธฐ")
char_count = gr.Textbox(label="๊ธ์ ์ ํ์ธ", value="๊ณต๋ฐฑ ํฌํจ: 0์", interactive=False)
# === ๋ณํ ๋ฒํผ ํ (๋์ผ scaleยทsize, ์ด๊ธฐํ๋ ๋ง์ง๋ง ์๋ฆฌ) ===
with gr.Row(elem_classes="convert-row"):
btn_conv = gr.Button("โจ ๋ณํํ๊ธฐ", variant="primary")
btn_copy = gr.Button("๐ ๋ณต์ฌ", variant="secondary")
btn_clr = gr.Button("๐๏ธ ์ด๊ธฐํ", variant="stop")
with gr.Column():
output_html = gr.HTML(value='<div id="prompter_label_space">๐บ ํ๋กฌํํฐ ๋ทฐ</div><div id="prompter_output_div" style="font-size:22px;"></div>', elem_id="prompter_html_wrap")
with gr.Accordion("๐ ํ
์คํธ ๊ฒฐ๊ณผ (ํด๋ฆญํ์ฌ ํผ์น๊ธฐ)", open=False):
output_text = gr.Textbox(lines=8, show_label=False, elem_id="output_text_area")
marker_collection = gr.Textbox(label="๐จ ์์ ํ์ ๋จ์ด (@@)", interactive=False, lines=2)
gr.Markdown("---")
gr.Markdown("**๐ก ๋๋ง์ ๋ฐ์ ์ฌ์ ์ถ๊ฐ** โ ๋จ์ด์ฅ์ด ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ๋ฐ์ ๊ต์ ์๋จ์
๋๋ค.")
with gr.Row():
nw = gr.Textbox(label="๋จ์ด")
np = gr.Textbox(label="์ํ๋ ๋ฐ์")
with gr.Column():
btn_add = gr.Button("๐พ ์ ์ฉ ๋ฐ ๋ณํ", variant="primary")
btn_clear_dict_inputs = gr.Button("๐งน ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ", variant="secondary")
status = gr.Textbox(label="์ ์ฅ ์ํ", interactive=False)
# [v151] ๋ฑ๋ก๋ ๋จ์ด ์ค ์๋ชป ๋ฑ๋กํ ๊ฒ์ ๊ณจ๋ผ ์์ /์ญ์
with gr.Accordion("โ๏ธ ๋จ์ด์ฅ ํญ๋ชฉ ์์ /์ญ์ (v151)", open=False):
gr.Markdown("๋จ์ด ์ ํ ์ ํ์ฌ ๋ฐ์์ด ์๋์ผ๋ก ์ฑ์์ง๋๋ค. ์ ๋ฐ์์ ์
๋ ฅํ๊ณ [โ๏ธ ๋ฐ์ ์์ ], ์์ ํ ์ง์ธ ๋๋ [๐๏ธ ์ญ์ ]๋ฅผ ๋๋ฅด์ธ์.")
with gr.Row():
dict_keys_dd = gr.Dropdown(choices=[], label="๋ฑ๋ก๋ ๋จ์ด ์ ํ", interactive=True)
edit_pron = gr.Textbox(label="์ ๋ฐ์ (์์ ์)")
with gr.Row():
btn_update_entry = gr.Button("โ๏ธ ๋ฐ์ ์์ ", variant="primary")
btn_delete_entry = gr.Button("๐๏ธ ์ ํ ๋จ์ด ์ญ์ ", variant="stop")
btn_refresh_choices = gr.Button("๐ ๋ชฉ๋ก ์๋ก๊ณ ์นจ", variant="secondary")
# [v153] ์์ธ ๋จ์ด(ํ์ดํธ๋ฆฌ์คํธ) โ ์ฌ์ ์นํ์์ ์ ์ธํ ์ด์ /ํฉ์ฑ์ด
with gr.Accordion("๐ก๏ธ ์์ธ ๋จ์ด(ํ์ดํธ๋ฆฌ์คํธ) (v153)", open=False):
gr.Markdown(
"**๋จ์ด์ฅ ์นํ์์ ์์ ํ ์ ์ธํ ๋จ์ด**๋ฅผ ๋ฑ๋กํฉ๋๋ค. "
"์: `์์ค์ปฌ๋ ์ดํฐ`, `์์คํ๋ ์`, `ํด๋ฆฌ์์คํฐ` ์ฒ๋ผ ์ฌ์ ์ `์์คโ์ค๋ชฐ`์ด ์์ด๋ "
"์ด ๋จ์ด๋ค์ ์๋ฌธ ๊ทธ๋๋ก ์ ์ง๋ฉ๋๋ค. **์ ํํ ์ผ์นํ๋ ๋ฌธ์์ด**๋ก ๋ฑ๋กํ์ธ์ "
"(๋ฌธ์์ด ๋ถ๋ถ์ผ์น ๋ฐฉ์์ด๋ผ `์์ค์ปฌ๋ ์ดํฐ`๋ก ๋ฑ๋กํ๋ฉด `์์ค์ปฌ๋ ์ดํฐ๋/์์ค์ปฌ๋ ์ดํฐ๋ฅผ`๋ ํจ๊ป ๋ณดํธ๋ฉ๋๋ค)."
)
with gr.Row():
wl_input = gr.Textbox(label="์์ธ๋ก ์ง์ ํ ๋จ์ด(์ด์ )", placeholder="์: ์์ค์ปฌ๋ ์ดํฐ")
wl_keys_dd = gr.Dropdown(choices=[], label="๋ฑ๋ก๋ ์์ธ ๋จ์ด ์ ํ", interactive=True)
with gr.Row():
btn_add_wl = gr.Button("โ ์์ธ ์ถ๊ฐ", variant="primary")
btn_del_wl = gr.Button("๐๏ธ ์ ํ ์์ธ ์ญ์ ", variant="stop")
btn_refresh_wl = gr.Button("๐ ์์ธ ๋ชฉ๋ก ์๋ก๊ณ ์นจ", variant="secondary")
proc_inputs = [input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl]
proc_outputs = [output_text, output_html, char_count, marker_collection]
btn_insert_marker.click(fn=None, inputs=[input_text], outputs=[input_text], js=insert_marker_js, api_name=False)
btn_insert_marker.click(fn=process_text, inputs=proc_inputs, outputs=proc_outputs, api_name=False)
btn_conv.click(fn=process_text, inputs=proc_inputs, outputs=proc_outputs, api_name=False)
btn_clr.click(fn=clear_all, outputs=[input_text, output_text, output_html, char_count, marker_collection], api_name=False)
btn_copy.click(fn=None, inputs=[output_text], outputs=None, js="(t) => { if(t) { navigator.clipboard.writeText(t); alert('โ
๋ณต์ฌ ์๋ฃ!'); } }", api_name=False)
btn_add.click(fn=add_and_update,
inputs=[nw, np, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl],
outputs=[status, output_text, output_html, char_count, marker_collection, user_temp_dict], api_name=False)
btn_add.click(fn=lambda: gr.update(choices=sorted(_read_local_dict().keys())), outputs=[dict_keys_dd], api_name=False)
btn_clear_dict_inputs.click(fn=lambda: ("", ""), outputs=[nw, np], api_name=False)
# [v151] ์์ /์ญ์ ํธ๋ค๋ฌ โ ์ ํ ๋ณ๊ฒฝ ์ ๊ธฐ์กด ๋ฐ์์ ํ๋ฆฌํ
dict_keys_dd.change(
fn=lambda key: _read_local_dict().get(key, "") if key else "",
inputs=[dict_keys_dd], outputs=[edit_pron], api_name=False,
)
btn_update_entry.click(
fn=update_dict_entry,
inputs=[dict_keys_dd, edit_pron, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl],
outputs=[status, output_text, output_html, char_count, marker_collection, dict_keys_dd, user_temp_dict], api_name=False,
)
btn_delete_entry.click(
fn=delete_dict_entry,
inputs=[dict_keys_dd, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl],
outputs=[status, output_text, output_html, char_count, marker_collection, dict_keys_dd, user_temp_dict], api_name=False,
)
btn_refresh_choices.click(
fn=update_choices, outputs=[dict_keys_dd], api_name=False,
)
iface.load(fn=update_choices, outputs=[dict_keys_dd], api_name=False)
# [v153] ํ์ดํธ๋ฆฌ์คํธ ํธ๋ค๋ฌ ๋ฐ์ธ๋ฉ
btn_add_wl.click(
fn=add_whitelist_entry,
inputs=[wl_input, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl],
outputs=[status, output_text, output_html, char_count, marker_collection, wl_keys_dd, user_temp_wl],
api_name=False,
)
btn_add_wl.click(fn=lambda: "", outputs=[wl_input], api_name=False) # ์
๋ ฅ์นธ ๋น์ฐ๊ธฐ
btn_del_wl.click(
fn=delete_whitelist_entry,
inputs=[wl_keys_dd, user_role, input_text, ai_mode, auto_break, smart_pause, font_size, user_temp_dict, user_temp_wl],
outputs=[status, output_text, output_html, char_count, marker_collection, wl_keys_dd, user_temp_wl],
api_name=False,
)
btn_refresh_wl.click(fn=refresh_whitelist_choices, outputs=[wl_keys_dd], api_name=False)
iface.load(fn=refresh_whitelist_choices, outputs=[wl_keys_dd], api_name=False)
for evt in [font_size.change, ai_mode.change, auto_break.change, smart_pause.change]:
evt(fn=process_text, inputs=proc_inputs, outputs=proc_outputs, api_name=False)
with gr.Tab("๐ฅ ์๋ ๋ฐฑ์
/์กฐํ/์์ "):
dl_btn = gr.DownloadButton("๐ฅ 1. ์ฌ์ ๋ฐฑ์
(PC ๋ค์ด๋ก๋)")
dl_btn.click(fn=get_file, outputs=[dl_btn], api_name=False)
gr.Markdown("---")
btn_load_json = gr.Button("๐ 2. ๋ฑ๋ก๋ ๋จ์ด์ฅ ๋ถ๋ฌ์ค๊ธฐ", variant="secondary")
json_input = gr.Textbox(lines=10, label="ํธ์ง์ฐฝ")
with gr.Row():
btn_apply_json = gr.Button("๐ ํ๋ฌ์ค(+) ํ๊ธฐ", variant="primary")
btn_overwrite_json = gr.Button("๐จ ์์ ํ ๋ฎ์ด์ฐ๊ธฐ (์ด๋๋ฏผ ์ ์ฉ)", variant="stop")
json_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False)
btn_load_json.click(fn=load_current_json_to_text, inputs=[user_temp_dict], outputs=[json_input, json_stat], api_name=False)
btn_apply_json.click(fn=apply_json_text, inputs=[json_input, user_role, user_temp_dict], outputs=[json_stat, user_temp_dict], api_name=False)
btn_overwrite_json.click(fn=overwrite_json_text, inputs=[json_input, user_role], outputs=[json_stat], api_name=False)
gr.Markdown("---")
with gr.Accordion("๐ค 3. ๋ฐฑ์
ํ์ผ๋ก ์ฌ์ ์ ๋ณํฉํ๊ธฐ", open=False):
up_file = gr.File(label="๋ฐฑ์
ํ์ผ ์
๋ก๋", type="filepath")
up_stat = gr.Textbox(label="์ํ ๊ฒฐ๊ณผ์ฐฝ", interactive=False)
up_file.upload(fn=upload_file, inputs=[up_file, user_role, user_temp_dict], outputs=[up_stat, user_temp_dict], api_name=False)
login_btn.click(fn=verify_login, inputs=[login_id, login_pw], outputs=[login_screen, main_app, user_role, login_msg, login_pw], api_name=False)
btn_logout.click(fn=perform_logout, inputs=[], outputs=[login_screen, main_app, user_role, login_msg, login_id, login_pw, user_temp_dict, user_temp_wl], api_name=False)
iface.load(fn=handle_page_load, inputs=[user_role], outputs=[login_screen, main_app, user_role, login_msg, login_id, login_pw], js=script_js)
if __name__ == "__main__":
iface.launch(**_LAUNCH_KW) |