Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files
app.py
CHANGED
@@ -44,6 +44,8 @@ def set_interface_language(lang):
|
|
44 |
"random_model": "⚔️ 随机模型",
|
45 |
"select_language": "选择语言(语言很重要,选择语言决定了角色扮演中AI用的语言)",
|
46 |
"select_language2": "选择语言",
|
|
|
|
|
47 |
"contant": """
|
48 |
## 联系我们
|
49 |
### 我们正在积极寻求更多模型愿意参与我们排行榜,
|
@@ -88,6 +90,8 @@ def set_interface_language(lang):
|
|
88 |
"random_model": "⚔️ Random Model",
|
89 |
"select_language": "Select a language (Language is important; the choice of language determines the language the AI will use in the roleplay)",
|
90 |
"select_language2": "Select a language",
|
|
|
|
|
91 |
"contant": """
|
92 |
## Contact Us
|
93 |
### We are actively seeking more models willing to participate in our leaderboard.
|
@@ -132,6 +136,8 @@ def set_interface_language(lang):
|
|
132 |
"random_model": "⚔️ ランダムモデル",
|
133 |
"select_language": "言語を選択してください(言語は非常に重要です。選択した言語はロールプレイでAIが使用する言語を決定します)",
|
134 |
"select_language2": "言語を選択してください",
|
|
|
|
|
135 |
"contant": """
|
136 |
## お問い合わせ
|
137 |
### 私たちは、リーダーボードに参加したいモデルを積極的に探しています。
|
@@ -177,6 +183,8 @@ def set_interface_language(lang):
|
|
177 |
"random_model": "⚔️ 랜덤 모델",
|
178 |
"select_language": "언어를 선택하세요 (언어는 매우 중요합니다. 선택한 언어는 역할 놀이에서 AI가 사용할 언어를 결정합니다)",
|
179 |
"select_language2": "언어를 선택하세요",
|
|
|
|
|
180 |
"contant": """
|
181 |
## 문의하기
|
182 |
### 우리는 리더보드에 참여할 의향이 있는 모델을 적극적으로 찾고 있습니다.
|
@@ -348,7 +356,7 @@ async def update_preset_prompt(char_id, language):
|
|
348 |
avatar_image_url = id_to_avatar(char_id)
|
349 |
response = requests.get(avatar_image_url)
|
350 |
image = Image.open(io.BytesIO(response.content))
|
351 |
-
resized_image = image.resize((
|
352 |
return gr.update(choices=preset_prompts), resized_image
|
353 |
|
354 |
|
@@ -358,7 +366,20 @@ def update_chat_and_avatar(moment):
|
|
358 |
while selected_models[0] == selected_models[1]:
|
359 |
selected_models = random.sample(models, 2)
|
360 |
print(selected_models)
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
|
364 |
def refresh_data(language):
|
@@ -392,12 +413,12 @@ def update_language(lang):
|
|
392 |
print("update_language", lang)
|
393 |
text = set_interface_language(lang)
|
394 |
characters = recommand_character(lang)
|
395 |
-
characters = [(item["
|
396 |
return (
|
397 |
text["title"],
|
398 |
text["intro"],
|
399 |
None,
|
400 |
-
gr.update(label=text["char_choice_label"],
|
401 |
gr.update(label=text["preset_prompt_label"]),
|
402 |
gr.update(value=text["refresh_button"]),
|
403 |
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
|
@@ -441,6 +462,38 @@ def init_and_update(request: gr.Request):
|
|
441 |
def passive_language_change(lang):
|
442 |
return gr.update(value=lang)
|
443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
with gr.Blocks() as demo:
|
446 |
# load 的时候就会刷新掉default_language
|
@@ -462,27 +515,40 @@ with gr.Blocks() as demo:
|
|
462 |
value=default_language.value,
|
463 |
)
|
464 |
with gr.Row():
|
465 |
-
with gr.Column(scale=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
avatar_image = gr.Image(scale=1, label=text["avatar_label"])
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
label=text["bio_label"],
|
484 |
-
placeholder=text["bio_placeholder"],
|
485 |
-
)
|
486 |
with gr.Row():
|
487 |
chatbox1 = gr.Chatbot(label=text["chatbox1_label"])
|
488 |
chatbox2 = gr.Chatbot(label=text["chatbox2_label"])
|
@@ -540,7 +606,23 @@ with gr.Blocks() as demo:
|
|
540 |
session_id1 = gr.State("")
|
541 |
session_id2 = gr.State("")
|
542 |
|
543 |
-
refresh_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
refresh_chat_button.click(
|
545 |
fn=refresh_chat,
|
546 |
inputs=[preset_prompt],
|
@@ -567,7 +649,7 @@ with gr.Blocks() as demo:
|
|
567 |
title,
|
568 |
intro,
|
569 |
avatar_image,
|
570 |
-
|
571 |
preset_prompt,
|
572 |
refresh_button,
|
573 |
bio,
|
@@ -594,9 +676,9 @@ with gr.Blocks() as demo:
|
|
594 |
inputs=language2,
|
595 |
outputs=language
|
596 |
)
|
597 |
-
|
598 |
fn=update_preset_prompt,
|
599 |
-
inputs=[
|
600 |
outputs=[preset_prompt, avatar_image],
|
601 |
)
|
602 |
preset_prompt.change(
|
@@ -723,7 +805,7 @@ with gr.Blocks() as demo:
|
|
723 |
title,
|
724 |
intro,
|
725 |
avatar_image,
|
726 |
-
|
727 |
preset_prompt,
|
728 |
refresh_button,
|
729 |
bio,
|
|
|
44 |
"random_model": "⚔️ 随机模型",
|
45 |
"select_language": "选择语言(语言很重要,选择语言决定了角色扮演中AI用的语言)",
|
46 |
"select_language2": "选择语言",
|
47 |
+
"char_choice_label": "选择角色",
|
48 |
+
"selected_char_label": "当前选择的角色",
|
49 |
"contant": """
|
50 |
## 联系我们
|
51 |
### 我们正在积极寻求更多模型愿意参与我们排行榜,
|
|
|
90 |
"random_model": "⚔️ Random Model",
|
91 |
"select_language": "Select a language (Language is important; the choice of language determines the language the AI will use in the roleplay)",
|
92 |
"select_language2": "Select a language",
|
93 |
+
"char_choice_label": "Select Character",
|
94 |
+
"selected_char_label": "Currently Selected Character",
|
95 |
"contant": """
|
96 |
## Contact Us
|
97 |
### We are actively seeking more models willing to participate in our leaderboard.
|
|
|
136 |
"random_model": "⚔️ ランダムモデル",
|
137 |
"select_language": "言語を選択してください(言語は非常に重要です。選択した言語はロールプレイでAIが使用する言語を決定します)",
|
138 |
"select_language2": "言語を選択してください",
|
139 |
+
"char_choice_label": "キャラクターを選択",
|
140 |
+
"selected_char_label": "現在選択されているキャラクター",
|
141 |
"contant": """
|
142 |
## お問い合わせ
|
143 |
### 私たちは、リーダーボードに参加したいモデルを積極的に探しています。
|
|
|
183 |
"random_model": "⚔️ 랜덤 모델",
|
184 |
"select_language": "언어를 선택하세요 (언어는 매우 중요합니다. 선택한 언어는 역할 놀이에서 AI가 사용할 언어를 결정합니다)",
|
185 |
"select_language2": "언어를 선택하세요",
|
186 |
+
"char_choice_label": "캐릭터 선택",
|
187 |
+
"selected_char_label": "현재 선택된 캐릭터",
|
188 |
"contant": """
|
189 |
## 문의하기
|
190 |
### 우리는 리더보드에 참여할 의향이 있는 모델을 적극적으로 찾고 있습니다.
|
|
|
356 |
avatar_image_url = id_to_avatar(char_id)
|
357 |
response = requests.get(avatar_image_url)
|
358 |
image = Image.open(io.BytesIO(response.content))
|
359 |
+
resized_image = image.resize((256, 256))
|
360 |
return gr.update(choices=preset_prompts), resized_image
|
361 |
|
362 |
|
|
|
366 |
while selected_models[0] == selected_models[1]:
|
367 |
selected_models = random.sample(models, 2)
|
368 |
print(selected_models)
|
369 |
+
|
370 |
+
# Resize the image
|
371 |
+
response = requests.get(moment["image_url"])
|
372 |
+
img = Image.open(io.BytesIO(response.content))
|
373 |
+
|
374 |
+
# Calculate new width to maintain aspect ratio
|
375 |
+
aspect_ratio = img.width / img.height
|
376 |
+
new_height = 768
|
377 |
+
new_width = int(new_height * aspect_ratio)
|
378 |
+
|
379 |
+
# Resize image
|
380 |
+
resized_img = img.resize((new_width, new_height))
|
381 |
+
|
382 |
+
return opening, opening, resized_img, "", "", selected_models
|
383 |
|
384 |
|
385 |
def refresh_data(language):
|
|
|
413 |
print("update_language", lang)
|
414 |
text = set_interface_language(lang)
|
415 |
characters = recommand_character(lang)
|
416 |
+
characters = [[id_to_avatar(item["_id"]), item["name"]] for item in characters] # 只保留头像和名称
|
417 |
return (
|
418 |
text["title"],
|
419 |
text["intro"],
|
420 |
None,
|
421 |
+
gr.update(label=text["char_choice_label"], value=characters),
|
422 |
gr.update(label=text["preset_prompt_label"]),
|
423 |
gr.update(value=text["refresh_button"]),
|
424 |
gr.update(placeholder=text["bio_placeholder"], label=text["bio_label"]),
|
|
|
462 |
def passive_language_change(lang):
|
463 |
return gr.update(value=lang)
|
464 |
|
465 |
+
async def get_character_gallery(language):
|
466 |
+
characters = recommand_character(language)
|
467 |
+
return [[id_to_avatar(char['_id']), char['name']] for char in characters]
|
468 |
+
|
469 |
+
def update_character_gallery(language):
|
470 |
+
characters = get_character_gallery(language)
|
471 |
+
return gr.update(value=characters)
|
472 |
+
|
473 |
+
def select_character(evt: gr.SelectData, gallery, language):
|
474 |
+
print(f"Event triggered. Index: {evt.index}")
|
475 |
+
print(f"Selected character from gallery: {gallery[evt.index]}")
|
476 |
+
|
477 |
+
selected_char = gallery[evt.index]
|
478 |
+
selected_char_id = os.path.basename(selected_char[0]).split('_')[1].split('.')[0]
|
479 |
+
print(f"Extracted character ID: {selected_char_id}")
|
480 |
+
|
481 |
+
characters = recommand_character(language)
|
482 |
+
print(f"Number of characters from recommand_character: {len(characters)}")
|
483 |
+
|
484 |
+
for char in characters:
|
485 |
+
if char['_id'].split('_')[1] == selected_char_id:
|
486 |
+
print(f"Match found: {char['name']}, {char['_id']}")
|
487 |
+
return char['name'], char['_id']
|
488 |
+
|
489 |
+
print("No match found")
|
490 |
+
return None, None
|
491 |
+
|
492 |
+
def refresh_character_gallery(language):
|
493 |
+
characters = recommand_character(language)
|
494 |
+
gallery_data = [[id_to_avatar(char['_id']), char['name']] for char in characters]
|
495 |
+
return gallery_data
|
496 |
+
|
497 |
|
498 |
with gr.Blocks() as demo:
|
499 |
# load 的时候就会刷新掉default_language
|
|
|
515 |
value=default_language.value,
|
516 |
)
|
517 |
with gr.Row():
|
518 |
+
with gr.Column(scale=4):
|
519 |
+
char_gallery = gr.Gallery(
|
520 |
+
label=text["char_choice_label"],
|
521 |
+
show_label=True,
|
522 |
+
elem_id="character_gallery",
|
523 |
+
columns=[5],
|
524 |
+
object_fit="contain",
|
525 |
+
height="auto",
|
526 |
+
interactive=True,
|
527 |
+
)
|
528 |
+
refresh_button = gr.Button(
|
529 |
+
text["refresh_button"], scale=1, variant="primary"
|
530 |
+
)
|
531 |
+
with gr.Column(scale=6):
|
532 |
+
preset_prompt = gr.Dropdown(
|
533 |
+
label=text["preset_prompt_label"], scale=3
|
534 |
+
)
|
535 |
avatar_image = gr.Image(scale=1, label=text["avatar_label"])
|
536 |
+
|
537 |
+
with gr.Row():
|
538 |
+
with gr.Column(scale=1):
|
539 |
+
selected_char_name = gr.Textbox(
|
540 |
+
label=text["selected_char_label"],
|
541 |
+
interactive=False
|
542 |
+
)
|
543 |
+
selected_char_id = gr.Textbox(
|
544 |
+
visible=False
|
545 |
+
)
|
546 |
+
with gr.Column(scale=3):
|
547 |
+
bio = gr.Textbox(
|
548 |
+
show_label=True,
|
549 |
+
label=text["bio_label"],
|
550 |
+
placeholder=text["bio_placeholder"]
|
551 |
+
)
|
|
|
|
|
|
|
552 |
with gr.Row():
|
553 |
chatbox1 = gr.Chatbot(label=text["chatbox1_label"])
|
554 |
chatbox2 = gr.Chatbot(label=text["chatbox2_label"])
|
|
|
606 |
session_id1 = gr.State("")
|
607 |
session_id2 = gr.State("")
|
608 |
|
609 |
+
refresh_button.click(
|
610 |
+
fn=refresh_character_gallery,
|
611 |
+
inputs=[language],
|
612 |
+
outputs=[char_gallery]
|
613 |
+
)
|
614 |
+
char_gallery.select(
|
615 |
+
fn=select_character,
|
616 |
+
inputs=[char_gallery, language],
|
617 |
+
outputs=[selected_char_name, selected_char_id]
|
618 |
+
)
|
619 |
+
|
620 |
+
selected_char_id.change(
|
621 |
+
fn=update_preset_prompt,
|
622 |
+
inputs=[selected_char_id, language],
|
623 |
+
outputs=[preset_prompt, avatar_image],
|
624 |
+
)
|
625 |
+
|
626 |
refresh_chat_button.click(
|
627 |
fn=refresh_chat,
|
628 |
inputs=[preset_prompt],
|
|
|
649 |
title,
|
650 |
intro,
|
651 |
avatar_image,
|
652 |
+
char_gallery,
|
653 |
preset_prompt,
|
654 |
refresh_button,
|
655 |
bio,
|
|
|
676 |
inputs=language2,
|
677 |
outputs=language
|
678 |
)
|
679 |
+
char_gallery.change(
|
680 |
fn=update_preset_prompt,
|
681 |
+
inputs=[char_gallery, language],
|
682 |
outputs=[preset_prompt, avatar_image],
|
683 |
)
|
684 |
preset_prompt.change(
|
|
|
805 |
title,
|
806 |
intro,
|
807 |
avatar_image,
|
808 |
+
char_gallery,
|
809 |
preset_prompt,
|
810 |
refresh_button,
|
811 |
bio,
|
group.jpg
CHANGED
utils.py
CHANGED
@@ -64,8 +64,8 @@ def load_dataframe():
|
|
64 |
elo_dict[model1] = calculate_elo(elo_dict[model1], elo_dict[model2], outcome=0.8)
|
65 |
elo_dict[model2] = calculate_elo(elo_dict[model2], elo_dict[model1], outcome=0.8)
|
66 |
elif winner == 'bothbad':
|
67 |
-
elo_dict[model1] = calculate_elo(elo_dict[model1], elo_dict[model2], outcome=0.
|
68 |
-
elo_dict[model2] = calculate_elo(elo_dict[model2], elo_dict[model1], outcome=0.
|
69 |
|
70 |
for model in models:
|
71 |
count = data['Model 1'].value_counts().get(model, 0) + data['Model 2'].value_counts().get(model, 0)
|
|
|
64 |
elo_dict[model1] = calculate_elo(elo_dict[model1], elo_dict[model2], outcome=0.8)
|
65 |
elo_dict[model2] = calculate_elo(elo_dict[model2], elo_dict[model1], outcome=0.8)
|
66 |
elif winner == 'bothbad':
|
67 |
+
elo_dict[model1] = calculate_elo(elo_dict[model1], elo_dict[model2], outcome=0.05)
|
68 |
+
elo_dict[model2] = calculate_elo(elo_dict[model2], elo_dict[model1], outcome=0.05)
|
69 |
|
70 |
for model in models:
|
71 |
count = data['Model 1'].value_counts().get(model, 0) + data['Model 2'].value_counts().get(model, 0)
|