Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
CHANGED
@@ -339,7 +339,7 @@ def select_winner(model1_name, model2_name, state, turn, anony, Language):
|
|
339 |
elif state == "bothbad":
|
340 |
result = f"투표해 주셔서 감사합니다. {model1_name} 과(와) {model2_name} 둘 다 나쁘다고 선택하셨습니다. 다음 테스트를 위해 새로 고침하세요."
|
341 |
update_model_stats(model1_name, model2_name, state, turn, anony, Language)
|
342 |
-
#
|
343 |
return (
|
344 |
result,
|
345 |
gr.update(interactive=False),
|
@@ -347,6 +347,7 @@ def select_winner(model1_name, model2_name, state, turn, anony, Language):
|
|
347 |
gr.update(interactive=False),
|
348 |
gr.update(interactive=False),
|
349 |
gr.update(interactive=False),
|
|
|
350 |
)
|
351 |
|
352 |
|
@@ -386,7 +387,7 @@ def update_chat_and_avatar(moment):
|
|
386 |
|
387 |
# Calculate new width to maintain aspect ratio
|
388 |
aspect_ratio = img.width / img.height
|
389 |
-
new_height =
|
390 |
new_width = int(new_height * aspect_ratio)
|
391 |
|
392 |
# Resize image
|
@@ -431,7 +432,7 @@ def update_language(lang):
|
|
431 |
text["intro"],
|
432 |
None,
|
433 |
gr.update(label=text["char_choice_label"], value=gallery_data),
|
434 |
-
gr.update(label=text["preset_prompt_label"]),
|
435 |
gr.update(value=text["refresh_button"]),
|
436 |
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
|
437 |
gr.update(label=text["chatbox1_label"]),
|
@@ -449,11 +450,14 @@ def update_language(lang):
|
|
449 |
gr.update(label=text["select_language"], value=lang),
|
450 |
text["score_instruction"],
|
451 |
text["contant"],
|
452 |
-
gr.update(value=lang,label=text["select_language2"]),
|
453 |
-
characters #
|
|
|
|
|
454 |
)
|
455 |
|
456 |
|
|
|
457 |
def auto_i18n(request: gr.Request):
|
458 |
print(request.headers["Accept-Language"])
|
459 |
if request.headers["Accept-Language"].split(",")[0].lower().startswith("zh"):
|
@@ -562,10 +566,18 @@ with gr.Blocks() as demo:
|
|
562 |
object_fit="contain",
|
563 |
height="auto",
|
564 |
interactive=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
565 |
)
|
566 |
refresh_button = gr.Button(
|
567 |
text["refresh_button"], scale=1, variant="primary"
|
568 |
-
|
569 |
with gr.Column(scale=6):
|
570 |
preset_prompt = gr.Dropdown(
|
571 |
label=text["preset_prompt_label"], scale=3
|
@@ -573,20 +585,11 @@ with gr.Blocks() as demo:
|
|
573 |
avatar_image = gr.Image(scale=1, label=text["avatar_label"])
|
574 |
|
575 |
with gr.Row():
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
selected_char_id = gr.Textbox(
|
582 |
-
visible=False
|
583 |
-
)
|
584 |
-
with gr.Column(scale=3):
|
585 |
-
bio = gr.Textbox(
|
586 |
-
show_label=True,
|
587 |
-
label=text["bio_label"],
|
588 |
-
placeholder=text["bio_placeholder"]
|
589 |
-
)
|
590 |
with gr.Row():
|
591 |
chatbox1 = gr.Chatbot(label=text["chatbox1_label"])
|
592 |
chatbox2 = gr.Chatbot(label=text["chatbox2_label"])
|
@@ -707,7 +710,9 @@ with gr.Blocks() as demo:
|
|
707 |
score_instruction,
|
708 |
contant,
|
709 |
language2,
|
710 |
-
characters_state # 新增的输出
|
|
|
|
|
711 |
],
|
712 |
)
|
713 |
language2.change(
|
@@ -750,6 +755,7 @@ with gr.Blocks() as demo:
|
|
750 |
tie_button,
|
751 |
bothbad_button,
|
752 |
battle_button,
|
|
|
753 |
],
|
754 |
)
|
755 |
model2win_button.click(
|
@@ -769,6 +775,7 @@ with gr.Blocks() as demo:
|
|
769 |
tie_button,
|
770 |
bothbad_button,
|
771 |
battle_button,
|
|
|
772 |
],
|
773 |
)
|
774 |
tie_button.click(
|
@@ -788,6 +795,7 @@ with gr.Blocks() as demo:
|
|
788 |
tie_button,
|
789 |
bothbad_button,
|
790 |
battle_button,
|
|
|
791 |
],
|
792 |
)
|
793 |
bothbad_button.click(
|
@@ -807,6 +815,7 @@ with gr.Blocks() as demo:
|
|
807 |
tie_button,
|
808 |
bothbad_button,
|
809 |
battle_button,
|
|
|
810 |
],
|
811 |
)
|
812 |
battle_button.click(
|
|
|
339 |
elif state == "bothbad":
|
340 |
result = f"투표해 주셔서 감사합니다. {model1_name} 과(와) {model2_name} 둘 다 나쁘다고 선택하셨습니다. 다음 테스트를 위해 새로 고침하세요."
|
341 |
update_model_stats(model1_name, model2_name, state, turn, anony, Language)
|
342 |
+
# 返回结果并让打分按钮置灰,同时重置chat_count
|
343 |
return (
|
344 |
result,
|
345 |
gr.update(interactive=False),
|
|
|
347 |
gr.update(interactive=False),
|
348 |
gr.update(interactive=False),
|
349 |
gr.update(interactive=False),
|
350 |
+
0 # 重置chat_count为0
|
351 |
)
|
352 |
|
353 |
|
|
|
387 |
|
388 |
# Calculate new width to maintain aspect ratio
|
389 |
aspect_ratio = img.width / img.height
|
390 |
+
new_height = 720
|
391 |
new_width = int(new_height * aspect_ratio)
|
392 |
|
393 |
# Resize image
|
|
|
432 |
text["intro"],
|
433 |
None,
|
434 |
gr.update(label=text["char_choice_label"], value=gallery_data),
|
435 |
+
gr.update(label=text["preset_prompt_label"], choices=[], value=None),
|
436 |
gr.update(value=text["refresh_button"]),
|
437 |
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
|
438 |
gr.update(label=text["chatbox1_label"]),
|
|
|
450 |
gr.update(label=text["select_language"], value=lang),
|
451 |
text["score_instruction"],
|
452 |
text["contant"],
|
453 |
+
gr.update(value=lang, label=text["select_language2"]),
|
454 |
+
characters, # 更新 characters_state
|
455 |
+
gr.update(value=None), # 重置 selected_char_name
|
456 |
+
gr.update(value=None), # 重置 selected_char_id
|
457 |
)
|
458 |
|
459 |
|
460 |
+
|
461 |
def auto_i18n(request: gr.Request):
|
462 |
print(request.headers["Accept-Language"])
|
463 |
if request.headers["Accept-Language"].split(",")[0].lower().startswith("zh"):
|
|
|
566 |
object_fit="contain",
|
567 |
height="auto",
|
568 |
interactive=True,
|
569 |
+
allow_preview=False
|
570 |
+
)
|
571 |
+
selected_char_name = gr.Textbox(
|
572 |
+
label=text["selected_char_label"],
|
573 |
+
interactive=False
|
574 |
+
)
|
575 |
+
selected_char_id = gr.Textbox(
|
576 |
+
visible=False
|
577 |
)
|
578 |
refresh_button = gr.Button(
|
579 |
text["refresh_button"], scale=1, variant="primary"
|
580 |
+
)
|
581 |
with gr.Column(scale=6):
|
582 |
preset_prompt = gr.Dropdown(
|
583 |
label=text["preset_prompt_label"], scale=3
|
|
|
585 |
avatar_image = gr.Image(scale=1, label=text["avatar_label"])
|
586 |
|
587 |
with gr.Row():
|
588 |
+
bio = gr.Textbox(
|
589 |
+
show_label=True,
|
590 |
+
label=text["bio_label"],
|
591 |
+
placeholder=text["bio_placeholder"]
|
592 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
with gr.Row():
|
594 |
chatbox1 = gr.Chatbot(label=text["chatbox1_label"])
|
595 |
chatbox2 = gr.Chatbot(label=text["chatbox2_label"])
|
|
|
710 |
score_instruction,
|
711 |
contant,
|
712 |
language2,
|
713 |
+
characters_state, # 新增的输出
|
714 |
+
selected_char_name, # 新增的输出
|
715 |
+
selected_char_id, # 新增的输出
|
716 |
],
|
717 |
)
|
718 |
language2.change(
|
|
|
755 |
tie_button,
|
756 |
bothbad_button,
|
757 |
battle_button,
|
758 |
+
chat_count
|
759 |
],
|
760 |
)
|
761 |
model2win_button.click(
|
|
|
775 |
tie_button,
|
776 |
bothbad_button,
|
777 |
battle_button,
|
778 |
+
chat_count
|
779 |
],
|
780 |
)
|
781 |
tie_button.click(
|
|
|
795 |
tie_button,
|
796 |
bothbad_button,
|
797 |
battle_button,
|
798 |
+
chat_count
|
799 |
],
|
800 |
)
|
801 |
bothbad_button.click(
|
|
|
815 |
tie_button,
|
816 |
bothbad_button,
|
817 |
battle_button,
|
818 |
+
chat_count
|
819 |
],
|
820 |
)
|
821 |
battle_button.click(
|
utils.py
CHANGED
@@ -69,14 +69,15 @@ def load_dataframe():
|
|
69 |
|
70 |
for model in models:
|
71 |
count = data['Model 1'].value_counts().get(model, 0) + data['Model 2'].value_counts().get(model, 0)
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
# 将结果字典转换为DataFrame
|
82 |
result_df = pd.DataFrame(results)
|
|
|
69 |
|
70 |
for model in models:
|
71 |
count = data['Model 1'].value_counts().get(model, 0) + data['Model 2'].value_counts().get(model, 0)
|
72 |
+
if count > 5: # Only include models with more than 5 participations
|
73 |
+
win_count = 0
|
74 |
+
win_count += len(data[(data['Winner'] == 'Model 1') & (data['Model 1'] == model)])
|
75 |
+
win_count += len(data[(data['Winner'] == 'Model 2') & (data['Model 2'] == model)])
|
76 |
+
win_count += len(data[(data['Winner'] == 'tie') & ((data['Model 1'] == model) | (data['Model 2'] == model))])
|
77 |
+
results['模型名称'].append(model)
|
78 |
+
results['参赛次数'].append(count)
|
79 |
+
results['胜利次数'].append(win_count)
|
80 |
+
results['ELO'].append(round(elo_dict[model]))
|
81 |
|
82 |
# 将结果字典转换为DataFrame
|
83 |
result_df = pd.DataFrame(results)
|