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,
    )