Spaces:
Runtime error
Runtime error
File size: 39,984 Bytes
d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 87ecac3 d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 87ecac3 d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 87ecac3 d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 87ecac3 d5de47d 86d0f8b d5de47d 39640b5 d5de47d 39640b5 d5de47d 32a87bd d5de47d 87ecac3 27f9849 d5de47d 87ecac3 39640b5 87ecac3 d5de47d 86d0f8b d5de47d 86d0f8b 39640b5 d5de47d 39640b5 d5de47d 39640b5 d5de47d 86d0f8b d5de47d 87ecac3 86d0f8b 87ecac3 d5de47d 86d0f8b d5de47d 87ecac3 39640b5 87ecac3 39640b5 87ecac3 d5de47d 87ecac3 39640b5 d5de47d 87ecac3 86d0f8b 87ecac3 86d0f8b 87ecac3 86d0f8b 87ecac3 d5de47d 87ecac3 d5de47d 86d0f8b 39640b5 d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 39640b5 d5de47d 39640b5 d5de47d 39640b5 d5de47d 39640b5 d5de47d 87ecac3 d5de47d 86d0f8b d5de47d 86d0f8b d5de47d 6427d29 |
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 |
# ruff: noqa
import random
import requests
import io
import gradio as gr
import pandas as pd
from PIL import Image
from useapi import *
from utils import *
def set_interface_language(lang):
if lang == "Chinese":
return {
"title": "# LLM่ง่ฒๆฎๆผ็ซๆๅบ๏ผๅจ่ง่ฒๆฎๆผๅบๆฏไธญ่ฏไผฐLLMs็่กจ็ฐ\n\n## ็น่ตโค๏ธ่ฟไธชSpace๏ผไธๆฌก่ฟ่ฝๆพๅฐ๏ผ",
"intro": """
## ๐ ่งๅ
#### ยท ไธไธคไธชๅฟๅ็ๆจกๅ๏ผไพๅฆ Claude, Gemini, Llama ๏ผๅๆถ่ฟ่ก่ง่ฒๆฎๆผ๏ผไปไปฌไผๆไธบไธไธช็ธๅ็่ง่ฒ๏ผ๏ผๆ็ฅจ้ๅบๆดๅฅฝ็้ฃไธช
#### ยท ไฝ ๅฏไปฅไธ็ดๅฏน่ฏ็ดๅฐ้ๅบ่ตขๅฎถ(ๅ่ฝฎๅฏน่ฏไธ้ๆฏ5่ฝฎ)
#### ยท ๆณ่ฆๅผๅงๅฏน่ฏ๏ผๆจ้่ฆๅ
ๅจ"้ๆฉ่ง่ฒ"ไธญ้ๆฉไธไธช่ง่ฒ๏ผไนๅๆจ้่ฆๅจ"้ๆฉๆถๅป"ไธญ้ๆฉไธไธชๆถๅป๏ผๆถๅปๆฏ็ป่ง่ฒ้ไธไธชๅบๆฏๅๅผๅบ็ฝ๏ผ่ฟๆ ทๅฏไปฅไธ่ง่ฒๅจๆณ่ฆ็ๅบๆฏไธญ่ฟ่กๅฏน่ฏใ
### [่ง่ฒๆฅ่ชRubii.ai, ๆณ่ฆๅ่ง่ฒ่ฟ่กๆด้ฟไน
็่ง่ฒๆฎๆผ๏ผๆฅRubii.aiๅงใ](https://rubii.ai/)
### [ๅจ็บฟๅ
่ดน่ฏญ้ณๅๆไปฅๅๅฃฐ้ณๅ
้](https://huggingface.co/spaces/YoMioAI/Free-Zero-shot-TTS-by-GSV-Infer-Engine)
""",
"avatar_label": "่ง่ฒๅพ็",
"char_choice_label": "้ๆฉ่ง่ฒ",
"preset_prompt_label": "้ๆฉๆถๅป",
"refresh_button": "ๅทๆฐ่ง่ฒๅ่กจ",
"bio_label": "่พๅ
ฅไฝ ็่ช่ฎพ",
"bio_placeholder": "ๆ็ๅๅญๅซRubii",
"chatbox1_label": "Model 1 ็็ญๅค",
"chatbox2_label": "Model 2 ็็ญๅค",
"user_input_placeholder": "ๅจๆญค่พๅ
ฅๅฏน่ฏ",
"battle_button": "ๅ้",
"score_instruction": "ๅจ่ทๅพ็ญๅคๅๅฏไฝฟ็จไปฅไธๅไธชๆ้ฎๅฏนๆฌ่ฝฎๅฏน่ฏๆๅ",
"model1win_button": "Model 1 ๆๆๆดๅฅฝ",
"model2win_button": "Model 2 ๆๆๆดๅฅฝ",
"tie_button": "ๆๆไธๆ ทๅฅฝ",
"bothbad_button": "ๆๆ้ฝไธๅฅฝ",
"result_placeholder": "็ปๆ: ",
"refresh_chat_button": "ๅทๆฐๅฏน่ฏ",
"ranking_tab": "๐ ๆจกๅๆ่ก",
"model_name_header": "ๆจกๅๅ็งฐ",
"contest_count_header": "ๅ่ตๆฌกๆฐ",
"win_rate_header": "ๆจกๅ่็",
"random_model": "โ๏ธ ้ๆบๆจกๅ",
"select_language": "้ๆฉ่ฏญ่จ๏ผ่ฏญ่จๅพ้่ฆ๏ผ้ๆฉ่ฏญ่จๅณๅฎไบ่ง่ฒๆฎๆผไธญAI็จ็่ฏญ่จ๏ผ",
"select_language2": "้ๆฉ่ฏญ่จ",
"char_choice_label": "้ๆฉ่ง่ฒ",
"selected_char_label": "ๅฝๅ้ๆฉ็่ง่ฒ",
"contant": """
## ่็ณปๆไปฌ
### [ๆๆฏ่ฎจ่ฎบ๏ผๆๆไปปไฝ้ฎ้ข๏ผๆๆฏๅฏนLLM่ง่ฒๆฎๆผๆๅ
ด่ถฃ๏ผๆฌข่ฟๅ ๅ
ฅๆไปฌ็Discord](https://discord.gg/DyECTyqhkC)
### ๆไปฌๆญฃๅจ็งฏๆๅฏปๆฑๆดๅคๆจกๅๆฟๆๅไธๆไปฌๆ่กๆฆ๏ผ
### ๆไปฌไนๅจๅฏปๆฑๅไฝ๏ผๅฆๆๆจๆๆ็่ฏ๏ผๆฌข่ฟ่ฏท่็ณปๆไปฌใ**Email:** [[email protected]](mailto:[email protected])
## ๆๅกๆกๆฌพ
### ็จๆทๅจไฝฟ็จๆๅกไนๅ้ๅๆไปฅไธๆกๆฌพ๏ผ
### ่ฏฅๆๅกไธบ็ ็ฉถ้ข่ง็ใๅฎไป
ๆไพๆ้็ๅฎๅ
จๆชๆฝ๏ผๅฏ่ฝไผ็ๆๅ็ฏๆงๅ
ๅฎนใไธๅพๅฐ่ฏฅๆๅก็จไบไปปไฝ้ๆณใๆๅฎณใๆดๅใ็งๆไธปไนๆๆง็ธๅ
ณ็็ฎ็ใ่ฏทๅฟไธไผ ไปปไฝ็งไบบไฟกๆฏใ่ฏฅๆๅกไผๆถ้็จๆท็ๅฏน่ฏๆฐๆฎ๏ผๅ
ๆฌๆๅญๅๅพๅ๏ผๅนถไฟ็ๅจๅไฝๅ
ฑ็จ็ฝฒๅ๏ผCC-BY๏ผๆ็ฑปไผผ่ฎธๅฏ่ฏไธๅๅ่ฟไบๆฐๆฎ็ๆๅฉใ
""",
}
elif lang == "English":
return {
"title": "# Roleplay LLM Arena: Benchmarking LLMs in the Roleplay Scenario\n\n## Likeโค๏ธ this Space, you can find it next time!",
"intro": """
## ๐ Rules
#### ยท Engage in roleplay with two anonymous models (e.g., Claude, Gemini, Llama) simultaneously, as they take on the same character. Vote for the one that performs better.
#### ยท You can continue the conversation until you select a winner (the maximum number of dialogue rounds per session is 5).
#### ยท To start the comparison, you need to first select a character in "Choose Character." Then, you need to select a "Moment" in "Choose Moment." A moment is used to set a scene and opening line for the character, allowing you to converse with the character in the desired scenario.
### [Characters are from Rubii.ai. Want to roleplay with characters for a longer time? Come to Rubii.ai.](https://rubii.ai/)
### [Online free voice synthesis and voice cloning](https://huggingface.co/spaces/YoMioAI/Free-Zero-shot-TTS-by-GSV-Infer-Engine)
""",
"avatar_label": "Character Image",
"char_choice_label": "Select Character",
"preset_prompt_label": "Select Moment",
"refresh_button": "Refresh Character List",
"bio_label": "Enter your bio",
"bio_placeholder": "My name is Rubii.",
"chatbox1_label": "Model 1's Response",
"chatbox2_label": "Model 2's Response",
"user_input_placeholder": "Enter conversation here",
"battle_button": "Send",
"score_instruction": "Use the following four buttons to score this round after receiving the response",
"model1win_button": "Model 1 is better",
"model2win_button": "Model 2 is better",
"tie_button": "Both are equally good",
"bothbad_button": "Both are bad",
"result_placeholder": "Result: ",
"refresh_chat_button": "Refresh Conversation",
"ranking_tab": "๐ Model Ranking",
"model_name_header": "Model Name",
"contest_count_header": "Contest Count",
"win_rate_header": "Win Rate",
"random_model": "โ๏ธ Random Model",
"select_language": "Select a language (Language is important; the choice of language determines the language the AI will use in the roleplay)",
"select_language2": "Select a language",
"char_choice_label": "Select Character",
"selected_char_label": "Currently Selected Character",
"contant": """
## Contact Us
### [Technical discussion, or any questions, or if you are interested in LLM roleplay, welcome to join our Discord](https://discord.gg/DyECTyqhkC)
### We are actively seeking more models willing to participate in our leaderboard.
### We are also looking for collaboration opportunities. If you are interested, please contact us. **Email:** [[email protected]](mailto:[email protected]).
## Terms of Service
### Users must agree to the following terms before using the service:
### This service is a research preview. It provides limited safety measures and may generate offensive content. The service should not be used for any illegal, harmful, violent, racist, or sexually related purposes. Please do not upload any personal information. The service collects user conversation data, including text and images, and reserves the right to distribute this data under Creative Commons Attribution (CC-BY) or similar licenses.
""",
}
elif lang == "Japanese":
return {
"title": "# LLMใญใผใซใใฌใคใขใชใผใ๏ผใญใผใซใใฌใคใทใใชใชใงใฎLLMใฎใใใฉใผใใณในใ่ฉไพก\n\n## Likeโค๏ธthis Space๏ผ",
"intro": """
## ๐ ใซใผใซ
#### ยท 2ใคใฎๅฟๅใขใใซ๏ผไพ: Claude, Gemini, Llama๏ผใจๅๆใซใญใผใซใใฌใคใ่กใ๏ผๅฝผใใฏๅใใญใฃใฉใฏใฟใผใซใชใใพใ๏ผใใใ่ฏใๆนใซๆ็ฅจใใฆใใ ใใใ
#### ยท ๅ่
ใๆฑบใพใใพใงไผ่ฉฑใ็ถใใใใจใใงใใพใ๏ผ1ใฟใผใณใใใใฎไผ่ฉฑใฎไธ้ใฏ5ใฟใผใณใงใ๏ผใ
#### ยท ไผ่ฉฑใๅงใใใซใฏใใพใใใญใฃใฉใฏใฟใผใ้ธๆใใงใญใฃใฉใฏใฟใผใ้ธๆใใใๆๅปใ้ธๆใใงใทใผใณใจใชใผใใใณใฐใ้ธๆใใฆใใ ใใใใใใซใใใใญใฃใฉใฏใฟใผใจๆใใทใผใณใงไผ่ฉฑใใงใใพใใ
### [ใญใฃใฉใฏใฟใผใฏRubii.aiใใๆฅใฆใใพใใใญใฃใฉใฏใฟใผใจใฎใญใผใซใใฌใคใใใ้ทใ็ถใใใๅ ดๅใฏใRubii.aiใซๆฅใฆใใ ใใใ](https://rubii.ai/)
### [ใชใณใฉใคใณ็กๆ้ณๅฃฐๅๆใจๅฃฐใฎใฏใญใผใณ](https://huggingface.co/spaces/YoMioAI/Free-Zero-shot-TTS-by-GSV-Infer-Engine)
""",
"avatar_label": "ใญใฃใฉใฏใฟใผ็ปๅ",
"char_choice_label": "ใญใฃใฉใฏใฟใผใ้ธๆ",
"preset_prompt_label": "ๆๅปใ้ธๆ",
"refresh_button": "ใญใฃใฉใฏใฟใผใชในใใๆดๆฐ",
"bio_label": "ใใชใใฎใใญใใฃใผใซใๅ
ฅๅ",
"bio_placeholder": "็งใฎๅๅใฏRubii",
"chatbox1_label": "Model 1 ใฎๅฟ็ญ",
"chatbox2_label": "Model 2 ใฎๅฟ็ญ",
"user_input_placeholder": "ใใใซใกใใปใผใธใๅ
ฅๅ",
"battle_button": "้ไฟก",
"score_instruction": "ๅฟ็ญใๅใๅใฃใๅพใไปฅไธใฎ4ใคใฎใใฟใณใงใใฎใฟใผใณใฎไผ่ฉฑใ่ฉไพกใงใใพใ",
"model1win_button": "Model 1 ใใใ่ฏใ",
"model2win_button": "Model 2 ใใใ่ฏใ",
"tie_button": "ๅใใใใ่ฏใ",
"bothbad_button": "ใฉใกใใ่ฏใใชใ",
"result_placeholder": "็ตๆ: ",
"refresh_chat_button": "ไผ่ฉฑใๆดๆฐ",
"ranking_tab": "๐ ใขใใซใฉใณใญใณใฐ",
"model_name_header": "ใขใใซๅ",
"contest_count_header": "ๅๅ ๅๆฐ",
"win_rate_header": "ใขใใซๅ็",
"random_model": "โ๏ธ ใฉใณใใ ใขใใซ",
"select_language": "่จ่ชใ้ธๆใใฆใใ ใใ๏ผ่จ่ชใฏ้ๅธธใซ้่ฆใงใใ้ธๆใใ่จ่ชใฏใญใผใซใใฌใคใงAIใไฝฟ็จใใ่จ่ชใๆฑบๅฎใใพใ๏ผ",
"select_language2": "่จ่ชใ้ธๆใใฆใใ ใใ",
"char_choice_label": "ใญใฃใฉใฏใฟใผใ้ธๆ",
"selected_char_label": "็พๅจ้ธๆใใใฆใใใญใฃใฉใฏใฟใผ",
"contant": """
## ใๅใๅใใ
### [ๆ่ก็ใช่ญฐ่ซใใพใใฏใ่ณชๅใใพใใฏLLMใญใผใซใใฌใคใซ่ๅณใใใๅ ดๅใฏใ็งใใกใฎDiscordใซใๅๅ ใใ ใใใ](https://discord.gg/DyECTyqhkC)
### ็งใใกใฏใใชใผใใผใใผใใซๅๅ ใใใใขใใซใ็ฉๆฅต็ใซๆขใใฆใใพใใ
### ็งใใกใฏใณใฉใใฌใผใทใงใณใฎๆฉไผใๆขใใฆใใพใใ่ๅณใใใๆนใฏใใใฒใ้ฃ็ตกใใ ใใใ**ใกใผใซ:** [[email protected]](mailto:[email protected])ใ
## ๅฉ็จ่ฆ็ด
### ใตใผใในใๅฉ็จใใๅใซใใฆใผใถใผใฏไปฅไธใฎ่ฆ็ดใซๅๆใใๅฟ
่ฆใใใใพใ๏ผ
### ๆฌใตใผใในใฏ็ ็ฉถใใฌใใฅใผ็ใงใใ้ใใใๅฎๅ
จๅฏพ็ญใๆไพใใฆใใใๆปๆ็ใชๅ
ๅฎนใ็ๆใใๅฏ่ฝๆงใใใใพใใๆฌใตใผใในใ้ๆณใๆๅฎณใๆดๅ็ใไบบ็จฎๅทฎๅฅ็ใใพใใฏๆง็ใช็ฎ็ใงไฝฟ็จใใชใใงใใ ใใใๅไบบๆ
ๅ ฑใฎใขใใใญใผใใฏ้ฟใใฆใใ ใใใๆฌใตใผใในใฏใฆใผใถใผใฎไผ่ฉฑใใผใฟ๏ผใใญในใใใใณ็ปๅ๏ผใๅ้ใใใฏใชใจใคใใฃใใปใณใขใณใบใปใฉใคใปใณใน๏ผCC-BY๏ผใพใใฏๅๆงใฎใฉใคใปใณในใฎไธใงใใใใฎใใผใฟใ้
ๅธใใๆจฉๅฉใไฟๆใใพใใ
""",
}
elif lang == "Korean":
return {
"title": "# LLM ์ญํ ์ํ ๊ฒฝ๊ธฐ์ฅ: ์ญํ ์ํ ์๋๋ฆฌ์ค์์ LLM์ ์ฑ๋ฅ ํ๊ฐ\n\n## Likeโค๏ธthis Space๏ผ",
"intro": """
## ๐ ๊ท์น
#### ยท ๋ ๊ฐ์ ์ต๋ช
์ ๋ชจ๋ธ(์: Claude, Gemini, Llama)๊ณผ ๋์์ ์ญํ ์ํ์ ์งํํ๊ณ , ๋ ๋์ ๋ชจ๋ธ์ ์ ํํ์ธ์.
#### ยท ์ฐ์น์๋ฅผ ์ ํํ ๋๊น์ง ๊ณ์ ๋ํ๋ฅผ ์งํํ ์ ์์ต๋๋ค(์ต๋ 5๋ผ์ด๋).
#### ยท ๋ํ๋ฅผ ์์ํ๋ ค๋ฉด ๋จผ์ "์บ๋ฆญํฐ ์ ํ"์์ ์บ๋ฆญํฐ๋ฅผ ์ ํํด์ผ ํ๋ฉฐ, ๊ทธ ๋ค์ "์๋๋ฆฌ์ค ์ ํ"์์ ์๋๋ฆฌ์ค๋ฅผ ์ ํํด์ผ ํฉ๋๋ค. ์๋๋ฆฌ์ค๋ ์บ๋ฆญํฐ์๊ฒ ์ฅ๋ฉด๊ณผ ์คํ๋์ ์ ๊ณตํ์ฌ ์ํ๋ ์๋๋ฆฌ์ค์์ ๋ํ๋ฅผ ์งํํ ์ ์๊ฒ ํฉ๋๋ค.
### [์บ๋ฆญํฐ๋ Rubii.ai์์ ์ค๊ณ ์์ต๋๋ค. ์บ๋ฆญํฐ์ ๋ ๊ธด ์ญํ ์ํ์ ํ๊ณ ์ถ์ผ์ ๊ฐ์? Rubii.ai๋ก ์ค์ธ์.](https://rubii.ai/)
### [์จ๋ผ์ธ ๋ฌด๋ฃ ์์ฑ ํฉ์ฑ ๋ฐ ์์ฑ ํด๋ก ](https://huggingface.co/spaces/YoMioAI/Free-Zero-shot-TTS-by-GSV-Infer-Engine)
""",
"avatar_label": "์บ๋ฆญํฐ ์ด๋ฏธ์ง",
"char_choice_label": "์บ๋ฆญํฐ ์ ํ",
"preset_prompt_label": "์๋๋ฆฌ์ค ์ ํ",
"refresh_button": "์บ๋ฆญํฐ ๋ชฉ๋ก ์๋ก๊ณ ์นจ",
"bio_label": "์์ ์ ์ค์ ์
๋ ฅ",
"bio_placeholder": "์ ์ด๋ฆ์ ๋ฃจ๋น์
๋๋ค.",
"chatbox1_label": "Model 1์ ์๋ต",
"chatbox2_label": "Model 2์ ์๋ต",
"user_input_placeholder": "์ฌ๊ธฐ์ ๋ํ ์
๋ ฅ",
"battle_button": "๋ณด๋ด๊ธฐ",
"score_instruction": "์๋ต์ ๋ฐ์ ํ ์๋ ๋ค ๊ฐ์ ๋ฒํผ์ ์ฌ์ฉํ์ฌ ์ด๋ฒ ๋ผ์ด๋๋ฅผ ํ๊ฐํ ์ ์์ต๋๋ค.",
"model1win_button": "Model 1์ด ๋ ๋์",
"model2win_button": "Model 2๊ฐ ๋ ๋์",
"tie_button": "๋๊ฐ์ด ์ข์",
"bothbad_button": "๋ ๋ค ๋ณ๋ก์",
"result_placeholder": "๊ฒฐ๊ณผ: ",
"refresh_chat_button": "๋ํ ์๋ก๊ณ ์นจ",
"ranking_tab": "๐ ๋ชจ๋ธ ์์",
"model_name_header": "๋ชจ๋ธ ์ด๋ฆ",
"contest_count_header": "์ฐธ๊ฐ ํ์",
"win_rate_header": "๋ชจ๋ธ ์น๋ฅ ",
"random_model": "โ๏ธ ๋๋ค ๋ชจ๋ธ",
"select_language": "์ธ์ด๋ฅผ ์ ํํ์ธ์ (์ธ์ด๋ ๋งค์ฐ ์ค์ํฉ๋๋ค. ์ ํํ ์ธ์ด๋ ์ญํ ๋์ด์์ AI๊ฐ ์ฌ์ฉํ ์ธ์ด๋ฅผ ๊ฒฐ์ ํฉ๋๋ค)",
"select_language2": "์ธ์ด๋ฅผ ์ ํํ์ธ์",
"char_choice_label": "์บ๋ฆญํฐ ์ ํ",
"selected_char_label": "ํ์ฌ ์ ํ๋ ์บ๋ฆญํฐ",
"contant": """
## ๋ฌธ์ํ๊ธฐ
### [๊ธฐ์ ์ ์ธ ๋
ผ์, ๋๋ ๋ฌธ์์ฌํญ, ๋๋ LLM ์ญํ ์ํ์ ๊ด์ฌ์ด ์์ผ์ค ๊ฒฝ์ฐ, ์ฐ๋ฆฌ์ Discord์ ์ฐธ์ฌํด ์ฃผ์ธ์.](https://discord.gg/DyECTyqhkC)
### ์ฐ๋ฆฌ๋ ๋ฆฌ๋๋ณด๋์ ์ฐธ์ฌํ ์ํฅ์ด ์๋ ๋ชจ๋ธ์ ์ ๊ทน์ ์ผ๋ก ์ฐพ๊ณ ์์ต๋๋ค.
### ์ฐ๋ฆฌ๋ ๋ํ ํ๋ ฅ ๊ธฐํ๋ฅผ ๋ชจ์ํ๊ณ ์์ต๋๋ค. ๊ด์ฌ์ด ์์ผ์๋ฉด ์ฐ๋ฝํด ์ฃผ์ธ์. **์ด๋ฉ์ผ:** [[email protected]](mailto:[email protected])
## ์ด์ฉ ์ฝ๊ด
### ์ฌ์ฉ์๋ ์๋น์ค๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ ๋ค์ ์ฝ๊ด์ ๋์ํด์ผ ํฉ๋๋ค:
### ์ด ์๋น์ค๋ ์ฐ๊ตฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ฒ์ ์
๋๋ค. ์ ํ๋ ์์ ์กฐ์น๋ฅผ ์ ๊ณตํ๋ฉฐ, ๋ถ์พํ ์ฝํ
์ธ ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค. ์ด ์๋น์ค๋ฅผ ๋ถ๋ฒ์ , ํด๋กญ๊ฑฐ๋, ํญ๋ ฅ์ ์ด๊ฑฐ๋, ์ธ์ข
์ฐจ๋ณ์ ์ด๊ฑฐ๋, ์ฑ์ ์ผ๋ก ๊ด๋ จ๋ ๋ชฉ์ ์ผ๋ก ์ฌ์ฉํ์ง ๋ง์ญ์์ค. ๊ฐ์ธ ์ ๋ณด๋ฅผ ์
๋ก๋ํ์ง ๋ง์ญ์์ค. ์ด ์๋น์ค๋ ์ฌ์ฉ์ ๋ํ ๋ฐ์ดํฐ(ํ
์คํธ ๋ฐ ์ด๋ฏธ์ง)๋ฅผ ์์งํ๋ฉฐ, ํฌ๋ฆฌ์์ดํฐ๋ธ ์ปค๋จผ์ฆ ์ ์์ ํ์(CC-BY) ๋๋ ์ ์ฌํ ๋ผ์ด์ ์ค ํ์ ์ด ๋ฐ์ดํฐ๋ฅผ ๋ฐฐํฌํ ๊ถ๋ฆฌ๋ฅผ ๋ณด์ ํฉ๋๋ค.
""",
}
async def run_battle(
user_input,
chatbox1,
chatbox2,
session_id1,
session_id2,
chat_count,
bio,
preset_prompt,
selected_models,
):
if chat_count >= 5:
chatbox1 = chatbox1 + [
(
"ๆจๅทฒ็ปๅจๆญคไฝ้ชไบๅคๆฌกๆจกๅๆๆไบ๏ผๅๅพ rubii.ai ็ปง็ปญๅฏน่ฏๅง",
"ๆจๅทฒ็ปๅจๆญคไฝ้ชไบๅคๆฌกๆจกๅๆๆไบ๏ผๅๅพ rubii.ai ็ปง็ปญๅฏน่ฏๅง",
)
]
chatbox2 = chatbox2 + [
(
"ๆจๅทฒ็ปๅจๆญคไฝ้ชไบๅคๆฌกๆจกๅๆๆไบ๏ผๅๅพ rubii.ai ็ปง็ปญๅฏน่ฏๅง",
"ๆจๅทฒ็ปๅจๆญคไฝ้ชไบๅคๆฌกๆจกๅๆๆไบ๏ผๅๅพ rubii.ai ็ปง็ปญๅฏน่ฏๅง",
)
]
yield (
chatbox1,
chatbox2,
selected_models[0],
selected_models[1],
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
session_id1,
session_id2,
chat_count,
gr.update(interactive=False),
gr.update(value=""),
)
return
chat_count += 1
chatbox1 = chatbox1 + [(user_input, "")]
chatbox2 = chatbox2 + [(user_input, "")]
yield (
chatbox1,
chatbox2,
selected_models[0],
selected_models[1],
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
session_id1,
session_id2,
chat_count,
gr.update(interactive=True),
gr.update(value=""),
)
response1 = ""
response2 = ""
async for chunk in combine_streams(
user_input,
user_input,
selected_models[0],
selected_models[1],
preset_prompt["_id"],
preset_prompt["_id"],
session_id1,
session_id2,
bio,
bio,
language,
):
if "requestA_header" in chunk:
session_id1 = chunk["requestA_header"]["x-session-id"]
if "requestB_header" in chunk:
session_id2 = chunk["requestB_header"]["x-session-id"]
if "requestA" in chunk:
response1 += chunk["requestA"]
if "requestB" in chunk:
response2 += chunk["requestB"]
chatbox1 = chatbox1[:-1] + [(user_input, response1)]
chatbox2 = chatbox2[:-1] + [(user_input, response2)]
yield (
chatbox1,
chatbox2,
selected_models[0],
selected_models[1],
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
gr.update(interactive=True),
session_id1,
session_id2,
chat_count,
gr.update(interactive=True),
gr.update(value=""),
)
def select_winner(model1_name, model2_name, state, turn, anony, Language):
if Language == "Chinese":
if state == "Model 1":
result = f"ๆ่ฐขๆจ็ๆ็ฅจ๏ผไฝ ้ๆฉไบ {state} - {model1_name} ๆๆๆดๅฅฝ๏ผ{model2_name} ๆๆๆดๅทฎ๏ผๅทๆฐไปฅ่ฟ่กไธไธ่ฝฎๆต่ฏ"
elif state == "Model 2":
result = f"ๆ่ฐขๆจ็ๆ็ฅจ๏ผไฝ ้ๆฉไบ {state} - {model2_name} ๆๆๆดๅฅฝ๏ผ{model1_name} ๆๆๆดๅทฎ๏ผๅทๆฐไปฅ่ฟ่กไธไธ่ฝฎๆต่ฏ"
elif state == "tie":
result = f"ๆ่ฐขๆจ็ๆ็ฅจ๏ผไฝ ้ๆฉไบ {model1_name} ไธ {model2_name} ๆๆ้ฝๅพๅฅฝ๏ผๅทๆฐไปฅ่ฟ่กไธไธ่ฝฎๆต่ฏ"
elif state == "bothbad":
result = f"ๆ่ฐขๆจ็ๆ็ฅจ๏ผไฝ ้ๆฉไบ {model1_name} ไธ {model2_name} ๆๆ้ฝไธๅฅฝ๏ผๅทๆฐไปฅ่ฟ่กไธไธ่ฝฎๆต่ฏ"
elif Language == "English":
if state == "Model 1":
result = f"Thank you for your vote. You chose {state} - {model1_name} performed better, {model2_name} performed worse. Refresh to proceed to the next round of testing."
elif state == "Model 2":
result = f"Thank you for your vote. You chose {state} - {model2_name} performed better, {model1_name} performed worse. Refresh to proceed to the next round of testing."
elif state == "tie":
result = f"Thank you for your vote. You selected that both {model1_name} and {model2_name} performed well. Refresh to proceed to the next round of testing."
elif state == "bothbad":
result = f"Thank you for your vote. You chose that both {model1_name} and {model2_name} performed poorly. Refresh to proceed to the next round of testing."
elif Language == "Japanese":
if state == "Model 1":
result = f"ๆ็ฅจใใใใจใใใใใพใใใใชใใฏ {state} - {model1_name} ใฎๆนใ่ฏใใ{model2_name} ใฏๅฃใฃใฆใใใจ้ธใณใพใใใๆฌกใฎใในใใ่กใใซใฏใชใใฌใใทใฅใใฆใใ ใใใ"
elif state == "Model 2":
result = f"ๆ็ฅจใใใใจใใใใใพใใใใชใใฏ {state} - {model2_name} ใฎๆนใ่ฏใใ{model1_name} ใฏๅฃใฃใฆใใใจ้ธใณใพใใใๆฌกใฎใในใใ่กใใซใฏใชใใฌใใทใฅใใฆใใ ใใใ"
elif state == "tie":
result = f"ๆ็ฅจใใใใจใใใใใพใใใใชใใฏ {model1_name} ใจ {model2_name} ใฎไธกๆนใ่ฏใใจ้ธใณใพใใใๆฌกใฎใในใใ่กใใซใฏใชใใฌใใทใฅใใฆใใ ใใใ"
elif state == "bothbad":
result = f"ๆ็ฅจใใใใจใใใใใพใใใใชใใฏ {model1_name} ใจ {model2_name} ใฎไธกๆนใ่ฏใใชใใจ้ธใณใพใใใๆฌกใฎใในใใ่กใใซใฏใชใใฌใใทใฅใใฆใใ ใใใ"
elif Language == "Korean":
if state == "Model 1":
result = f"ํฌํํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. {state} - {model1_name} ์ด(๊ฐ) ๋ ์ข๋ค๊ณ ์ ํํ์
จ์ต๋๋ค. {model2_name} ์ด(๊ฐ) ๋ ๋์ฉ๋๋ค. ๋ค์ ํ
์คํธ๋ฅผ ์ํด ์๋ก ๊ณ ์นจํ์ธ์."
elif state == "Model 2":
result = f"ํฌํํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. {state} - {model2_name} ์ด(๊ฐ) ๋ ์ข๋ค๊ณ ์ ํํ์
จ์ต๋๋ค. {model1_name} ์ด(๊ฐ) ๋ ๋์ฉ๋๋ค. ๋ค์ ํ
์คํธ๋ฅผ ์ํด ์๋ก ๊ณ ์นจํ์ธ์."
elif state == "tie":
result = f"ํฌํํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. {model1_name} ๊ณผ(์) {model2_name} ๋ ๋ค ์ข๋ค๊ณ ์ ํํ์
จ์ต๋๋ค. ๋ค์ ํ
์คํธ๋ฅผ ์ํด ์๋ก ๊ณ ์นจํ์ธ์."
elif state == "bothbad":
result = f"ํฌํํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. {model1_name} ๊ณผ(์) {model2_name} ๋ ๋ค ๋์๋ค๊ณ ์ ํํ์
จ์ต๋๋ค. ๋ค์ ํ
์คํธ๋ฅผ ์ํด ์๋ก ๊ณ ์นจํ์ธ์."
update_model_stats(model1_name, model2_name, state, turn, anony, Language)
# ่ฟๅ็ปๆๅนถ่ฎฉๆๅๆ้ฎ็ฝฎ็ฐ๏ผๅๆถ้็ฝฎchat_count
return (
result,
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=False),
0 # ้็ฝฎchat_countไธบ0
)
async def get_preset_prompts(char_id, language):
recommand_data = await recommand(char_id, language)
return [(item["name"], item) for item in recommand_data]
async def update_preset_prompt(char_id, language):
if not char_id:
return gr.update(), None
try:
preset_prompts = await get_preset_prompts(char_id, language)
except TypeError:
return gr.update(), None
avatar_image_url = id_to_avatar(char_id)
response = requests.get(avatar_image_url)
image = Image.open(io.BytesIO(response.content))
resized_image = image.resize((256, 256))
# ็ดๆฅๅจ่ฟ้่ฎพ็ฝฎ preset_prompt ็้ป่ฎคๅผไธบ็ฌฌไธไธช้้กน
if preset_prompts:
preset_prompt_update = gr.update(choices=preset_prompts, value=preset_prompts[0][1])
else:
preset_prompt_update = gr.update(choices=[], value=None)
return preset_prompt_update, resized_image
def update_chat_and_avatar(moment):
opening = [(None, moment["opening"])]
selected_models = random.sample(models, 2)
while selected_models[0] == selected_models[1]:
selected_models = random.sample(models, 2)
print(selected_models)
# Resize the image
response = requests.get(moment["image_url"])
img = Image.open(io.BytesIO(response.content))
# Calculate new width to maintain aspect ratio
aspect_ratio = img.width / img.height
new_height = 720
new_width = int(new_height * aspect_ratio)
# Resize image
resized_img = img.resize((new_width, new_height))
return opening, opening, resized_img, "", "", selected_models
def refresh_data(language):
characters = recommand_character(language)
characters = [(item["name"], item["_id"]) for item in characters]
return gr.update(choices=characters)
def refresh_chat(moment):
chatbox1, chatbox2, avatar_image, session_id1, session_id2, selected_models = (
update_chat_and_avatar(moment)
)
return (
chatbox1,
chatbox2,
avatar_image,
session_id1,
session_id2,
selected_models,
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=False),
gr.update(interactive=True),
gr.update(value="็ปๆ๏ผ"),
gr.update(value=0),
)
def update_language(lang):
print("update_language", lang)
text = set_interface_language(lang)
gallery_data, characters = refresh_character_gallery(lang)
return (
text["title"],
text["intro"],
None,
gr.update(label=text["char_choice_label"], value=gallery_data),
gr.update(label=text["preset_prompt_label"], choices=[], value=None),
gr.update(value=text["refresh_button"]),
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
gr.update(label=text["chatbox1_label"]),
gr.update(label=text["chatbox2_label"]),
gr.update(placeholder=text["user_input_placeholder"]),
gr.update(value=text["battle_button"]),
gr.update(placeholder=text["result_placeholder"]),
gr.update(value=text["refresh_chat_button"]),
gr.update(value=text["model1win_button"]),
gr.update(value=text["model2win_button"]),
gr.update(value=text["tie_button"]),
gr.update(value=text["bothbad_button"]),
gr.update(label=text["random_model"]),
gr.update(label=text["ranking_tab"]),
gr.update(label=text["select_language"], value=lang),
text["score_instruction"],
text["contant"],
gr.update(value=lang, label=text["select_language2"]),
characters, # ๆดๆฐ characters_state
gr.update(value=None), # ้็ฝฎ selected_char_name
gr.update(value=None), # ้็ฝฎ selected_char_id
)
def auto_i18n(request: gr.Request):
print(request.headers["Accept-Language"])
if request.headers["Accept-Language"].split(",")[0].lower().startswith("zh"):
language = "Chinese"
elif request.headers["Accept-Language"].split(",")[0].lower().startswith("en"):
language = "English"
elif request.headers["Accept-Language"].split(",")[0].lower().startswith("ja"):
language = "Japanese"
elif request.headers["Accept-Language"].split(",")[0].lower().startswith("ko"):
language = "Korean"
else:
language = "Chinese"
return language
def init_and_update(request: gr.Request):
detected_lang = auto_i18n(request)
text = set_interface_language(detected_lang)
gallery_data, characters = refresh_character_gallery(detected_lang)
return [
detected_lang,
text["title"],
text["intro"],
None,
gr.update(label=text["char_choice_label"], value=gallery_data),
gr.update(label=text["preset_prompt_label"]),
gr.update(value=text["refresh_button"]),
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
gr.update(label=text["chatbox1_label"]),
gr.update(label=text["chatbox2_label"]),
gr.update(placeholder=text["user_input_placeholder"]),
gr.update(value=text["battle_button"]),
gr.update(placeholder=text["result_placeholder"]),
gr.update(value=text["refresh_chat_button"]),
gr.update(value=text["model1win_button"]),
gr.update(value=text["model2win_button"]),
gr.update(value=text["tie_button"]),
gr.update(value=text["bothbad_button"]),
gr.update(label=text["random_model"]),
gr.update(label=text["ranking_tab"]),
gr.update(label=text["select_language"], value=detected_lang),
text["score_instruction"],
text["contant"],
characters # ๆฐๅข็่พๅบ
]
def passive_language_change(lang):
return gr.update(value=lang)
async def get_character_gallery(language):
characters = recommand_character(language)
return [[id_to_avatar(char['_id']), char['name']] for char in characters]
def update_character_gallery(language):
characters = get_character_gallery(language)
return gr.update(value=characters)
def refresh_character_gallery(language):
characters = recommand_character(language)
gallery_data = [[id_to_avatar(char['_id']), char['name']] for char in characters]
return gallery_data, characters
def select_character(evt: gr.SelectData, characters):
index = evt.index
print(f"Event triggered. Index: {index}")
if index >= len(characters):
return None, None
selected_char = characters[index]
selected_char_name = selected_char['name']
selected_char_id = selected_char['_id']
print(f"Selected character: {selected_char_name}, ID: {selected_char_id}")
return selected_char_name, selected_char_id
with gr.Blocks() as demo:
characters_state = gr.State(value=[])
# load ็ๆถๅๅฐฑไผๅทๆฐๆdefault_language
default_language = gr.State("Chinese")
language = "Chinese"
characters = recommand_character(language)
characters = [(item["name"], item["_id"]) for item in characters]
text = set_interface_language(default_language.value)
models = get_models()
with gr.Tab(text["random_model"]) as random_model_tab:
with gr.Column():
title = gr.Markdown(f"{text['title']}")
with gr.Column(scale=10):
intro = gr.Markdown(f"{text['intro']}")
with gr.Column(scale=1):
language = gr.Radio(
["English", "Chinese", "Japanese", "Korean"],
label=text["select_language"],
value=default_language.value,
)
with gr.Row():
with gr.Column(scale=4):
char_gallery = gr.Gallery(
label=text["char_choice_label"],
show_label=True,
elem_id="character_gallery",
columns=[5],
object_fit="contain",
height="auto",
interactive=True,
allow_preview=False
)
selected_char_name = gr.Textbox(
label=text["selected_char_label"],
interactive=False
)
selected_char_id = gr.Textbox(
visible=False
)
refresh_button = gr.Button(
text["refresh_button"], scale=1, variant="primary"
)
with gr.Column(scale=6):
preset_prompt = gr.Dropdown(
label=text["preset_prompt_label"], scale=3
)
avatar_image = gr.Image(scale=1, label=text["avatar_label"])
with gr.Row():
bio = gr.Textbox(
show_label=True,
label=text["bio_label"],
placeholder=text["bio_placeholder"]
)
with gr.Row():
chatbox1 = gr.Chatbot(label=text["chatbox1_label"])
chatbox2 = gr.Chatbot(label=text["chatbox2_label"])
with gr.Row():
user_input = gr.Textbox(
placeholder=text["user_input_placeholder"], scale=3, show_label=False
)
battle_button = gr.Button(text["battle_button"], scale=1, variant="primary")
with gr.Column():
score_instruction = gr.Markdown(f"{text['score_instruction']}")
with gr.Row():
model1win_button = gr.Button(
text["model1win_button"], variant="primary", interactive=False
)
model2win_button = gr.Button(
text["model2win_button"], variant="primary", interactive=False
)
tie_button = gr.Button(text["tie_button"], interactive=False)
bothbad_button = gr.Button(text["bothbad_button"], interactive=False)
with gr.Row():
result_output = gr.Textbox(
placeholder=text["result_placeholder"], scale=3, show_label=False
)
refresh_chat_button = gr.Button(
text["refresh_chat_button"], variant="secondary", scale=1
)
with gr.Tab(text["ranking_tab"]) as ranking_tab:
language2 = gr.Radio(
["English", "Chinese", "Japanese", "Korean"],
label=text["select_language"],
value=default_language.value,
)
gr.DataFrame(
load_dataframe,
datatype=["str", "str", "str", "str", "str"],
every=gr.Timer(10),
)
# ๆๅ
ฅ CSS ๆ ทๅผ๏ผ็จไบ้่ๅบ้จ็โ้่ฟ API ไฝฟ็จโ้พๆฅ
gr.HTML("""
<style>
footer {display: none !important;}
</style>
""")
with gr.Row():
with gr.Column(scale=5):
contant = gr.Markdown(f"{text['contant']}")
with gr.Column(scale=1):
gr.Image("group.jpg")
selected_models = gr.State([])
model1_state = gr.State("")
model2_state = gr.State("")
chat_count = gr.State(0)
session_id1 = gr.State("")
session_id2 = gr.State("")
refresh_button.click(
fn=refresh_character_gallery,
inputs=[language],
outputs=[char_gallery, characters_state]
)
char_gallery.select(
fn=select_character,
inputs=[characters_state],
outputs=[selected_char_name, selected_char_id]
)
selected_char_id.change(
fn=update_preset_prompt,
inputs=[selected_char_id, language],
outputs=[preset_prompt, avatar_image],
)
refresh_chat_button.click(
fn=refresh_chat,
inputs=[preset_prompt],
outputs=[
chatbox1,
chatbox2,
avatar_image,
session_id1,
session_id2,
selected_models,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
battle_button,
result_output,
chat_count,
],
)
language.change(
fn=update_language,
inputs=language,
outputs=[
title,
intro,
avatar_image,
char_gallery,
preset_prompt,
refresh_button,
bio,
chatbox1,
chatbox2,
user_input,
battle_button,
result_output,
refresh_chat_button,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
random_model_tab,
ranking_tab,
language,
score_instruction,
contant,
language2,
characters_state, # ๆฐๅข็่พๅบ
selected_char_name, # ๆฐๅข็่พๅบ
selected_char_id, # ๆฐๅข็่พๅบ
],
)
language2.change(
fn=passive_language_change,
inputs=language2,
outputs=language
)
char_gallery.select(
fn=select_character,
inputs=[characters_state],
outputs=[selected_char_name, selected_char_id]
)
preset_prompt.change(
fn=update_chat_and_avatar,
inputs=[preset_prompt],
outputs=[
chatbox1,
chatbox2,
avatar_image,
session_id1,
session_id2,
selected_models,
],
)
model1win_button.click(
fn=select_winner,
inputs=[
model1_state,
model2_state,
gr.State("Model 1"),
chat_count,
gr.State(True),
language,
],
outputs=[
result_output,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
battle_button,
chat_count
],
)
model2win_button.click(
fn=select_winner,
inputs=[
model1_state,
model2_state,
gr.State("Model 2"),
chat_count,
gr.State(True),
language,
],
outputs=[
result_output,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
battle_button,
chat_count
],
)
tie_button.click(
fn=select_winner,
inputs=[
model1_state,
model2_state,
gr.State("tie"),
chat_count,
gr.State(True),
language,
],
outputs=[
result_output,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
battle_button,
chat_count
],
)
bothbad_button.click(
fn=select_winner,
inputs=[
model1_state,
model2_state,
gr.State("bothbad"),
chat_count,
gr.State(True),
language,
],
outputs=[
result_output,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
battle_button,
chat_count
],
)
battle_button.click(
run_battle,
inputs=[
user_input,
chatbox1,
chatbox2,
session_id1,
session_id2,
chat_count,
bio,
preset_prompt,
selected_models,
],
outputs=[
chatbox1,
chatbox2,
model1_state,
model2_state,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
session_id1,
session_id2,
chat_count,
battle_button,
user_input,
],
)
demo.load(
init_and_update,
outputs=[
default_language,
title,
intro,
avatar_image,
char_gallery,
preset_prompt,
refresh_button,
bio,
chatbox1,
chatbox2,
user_input,
battle_button,
result_output,
refresh_chat_button,
model1win_button,
model2win_button,
tie_button,
bothbad_button,
random_model_tab,
ranking_tab,
language,
score_instruction,
contant,
characters_state # ๆฐๅข็่พๅบ
],
)
if __name__ == "__main__":
demo.queue(default_concurrency_limit=8).launch(
server_name="0.0.0.0",
server_port=7860,
)
|