|
import gradio as gr |
|
import pandas as pd |
|
import numpy as np |
|
from datetime import datetime, timedelta |
|
import random |
|
import json |
|
import os |
|
|
|
|
|
pinned_rows_global = set() |
|
|
|
|
|
def generate_llm_data(): |
|
"""从metadata/medical_data.json读取医疗大语言模型排行榜数据""" |
|
try: |
|
|
|
json_path = "metadata/medical_data.json" |
|
with open(json_path, 'r', encoding='utf-8') as f: |
|
data = json.load(f) |
|
|
|
|
|
df = pd.DataFrame(data) |
|
|
|
|
|
df = df.fillna("-") |
|
|
|
|
|
|
|
|
|
|
|
|
|
df_with_score = df[df['平均分'] != "-"].copy() |
|
df_without_score = df[df['平均分'] == "-"].copy() |
|
|
|
|
|
if not df_with_score.empty: |
|
df_with_score = df_with_score.sort_values('平均分', ascending=False) |
|
|
|
|
|
df_sorted = pd.concat([df_with_score, df_without_score], ignore_index=True) |
|
|
|
|
|
df_sorted['排名'] = range(1, len(df_sorted) + 1) |
|
|
|
|
|
|
|
all_columns = list(df_sorted.columns) |
|
|
|
|
|
new_columns = ['排名', '模型名称', '平均分'] |
|
|
|
|
|
other_columns = [col for col in all_columns if col not in new_columns] |
|
new_columns.extend(other_columns) |
|
|
|
|
|
df_sorted = df_sorted[new_columns] |
|
|
|
return df_sorted |
|
|
|
except FileNotFoundError: |
|
print(f"警告: 找不到文件 {json_path},使用默认数据") |
|
|
|
return pd.DataFrame() |
|
|
|
|
|
def generate_multimodal_data(): |
|
"""从metadata/medical_mm_data.json读取医疗多模态大模型排行榜数据""" |
|
try: |
|
|
|
json_path = "metadata/medical_mm_data.json" |
|
with open(json_path, 'r', encoding='utf-8') as f: |
|
data = json.load(f) |
|
|
|
|
|
df = pd.DataFrame(data) |
|
|
|
|
|
df = df.fillna("-") |
|
|
|
|
|
df = df[df['类型'] != '研究'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
df_with_score = df[df['平均分'] != "-"].copy() |
|
df_without_score = df[df['平均分'] == "-"].copy() |
|
|
|
|
|
if not df_with_score.empty: |
|
df_with_score = df_with_score.sort_values('平均分', ascending=False) |
|
|
|
|
|
df_sorted = pd.concat([df_with_score, df_without_score], ignore_index=True) |
|
|
|
|
|
df_sorted['排名'] = range(1, len(df_sorted) + 1) |
|
|
|
|
|
|
|
all_columns = list(df_sorted.columns) |
|
|
|
|
|
new_columns = ['排名', '模型名称', '平均分'] |
|
|
|
|
|
other_columns = [col for col in all_columns if col not in new_columns] |
|
new_columns.extend(other_columns) |
|
|
|
|
|
df_sorted = df_sorted[new_columns] |
|
|
|
return df_sorted |
|
|
|
except FileNotFoundError: |
|
print(f"警告: 找不到文件 {json_path},使用默认数据") |
|
|
|
return pd.DataFrame() |
|
|
|
def get_llm_leaderboard(): |
|
"""获取医疗大语言模型排行榜数据""" |
|
return generate_llm_data() |
|
|
|
def generate_llm_html_table(df=None, sort_column=None, sort_order="desc", pinned_rows=None): |
|
"""生成医疗大语言模型排行榜的HTML表格""" |
|
if df is None: |
|
df = get_llm_leaderboard() |
|
|
|
if df.empty: |
|
return "<p>暂无数据</p>" |
|
|
|
if pinned_rows is None: |
|
pinned_rows = set() |
|
|
|
|
|
if sort_column and sort_column in df.columns: |
|
|
|
if sort_column == '排名': |
|
|
|
df_for_sort = df.copy() |
|
df_for_sort['平均分_numeric'] = pd.to_numeric(df_for_sort['平均分'], errors='coerce') |
|
|
|
|
|
if sort_order == "desc": |
|
|
|
sorted_indices = df_for_sort.sort_values('平均分_numeric', ascending=False, na_position='last').index |
|
else: |
|
|
|
sorted_indices = df_for_sort.sort_values('平均分_numeric', ascending=True, na_position='last').index |
|
|
|
df = df.loc[sorted_indices].reset_index(drop=True) |
|
|
|
elif sort_column in ['平均分', 'MMMU-Med', 'VQA-RAD', 'SLAKE', 'PathVQA', 'PMC-VQA', 'OMVQA', 'MedXQA']: |
|
|
|
original_data = df.copy() |
|
|
|
|
|
df_for_sort = df.copy() |
|
df_for_sort[sort_column + '_numeric'] = pd.to_numeric(df_for_sort[sort_column], errors='coerce') |
|
|
|
|
|
if sort_order == "asc": |
|
sorted_indices = df_for_sort.sort_values(sort_column + '_numeric', ascending=True, na_position='last').index |
|
else: |
|
sorted_indices = df_for_sort.sort_values(sort_column + '_numeric', ascending=False, na_position='last').index |
|
|
|
|
|
df = original_data.loc[sorted_indices].reset_index(drop=True) |
|
else: |
|
|
|
ascending = sort_order == "asc" |
|
df = df.sort_values(sort_column, ascending=ascending, na_position='last').reset_index(drop=True) |
|
|
|
|
|
if pinned_rows: |
|
|
|
pinned_df = df[df['排名'].isin(pinned_rows)].copy() |
|
unpinned_df = df[~df['排名'].isin(pinned_rows)].copy() |
|
|
|
|
|
if not pinned_df.empty: |
|
pinned_df = pinned_df.sort_values('排名', ascending=True) |
|
|
|
|
|
|
|
|
|
|
|
if not pinned_df.empty: |
|
display_df = pd.concat([pinned_df, unpinned_df], ignore_index=True) |
|
else: |
|
display_df = unpinned_df |
|
else: |
|
|
|
display_df = df.reset_index(drop=True) |
|
|
|
|
|
display_df['row_id'] = display_df.index |
|
|
|
|
|
html = """ |
|
<div style="overflow-x: auto; width: 100%;"> |
|
<style> |
|
.sort-btn { |
|
background: none; |
|
border: none; |
|
cursor: pointer; |
|
margin-left: 5px; |
|
font-size: 12px; |
|
color: #007bff; |
|
padding: 2px 4px; |
|
border-radius: 3px; |
|
} |
|
.sort-btn:hover { |
|
background-color: #e9ecef; |
|
} |
|
.sort-btn:active { |
|
background-color: #dee2e6; |
|
} |
|
.pin-btn { |
|
background: none; |
|
border: none; |
|
cursor: pointer; |
|
font-size: 16px; |
|
padding: 2px 4px; |
|
margin-right: 8px; |
|
border-radius: 3px; |
|
} |
|
.pin-btn:hover { |
|
background-color: #e9ecef; |
|
} |
|
.pinned-row { |
|
background-color: #e3f2fd !important; |
|
border-left: 4px solid #2196f3 !important; |
|
} |
|
</style> |
|
<table style="width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 14px;"> |
|
<thead> |
|
<tr style="background-color: #f8f9fa; border-bottom: 2px solid #dee2e6;"> |
|
""" |
|
|
|
|
|
html += '<th style="padding: 12px 8px; text-align: center; border: 1px solid #dee2e6; font-weight: bold; width: 50px;">📌</th>' |
|
|
|
for col in display_df.columns: |
|
if col == 'row_id': |
|
continue |
|
html += f''' |
|
<th style="padding: 12px 8px; text-align: left; border: 1px solid #dee2e6; font-weight: bold;"> |
|
{col} |
|
</th> |
|
''' |
|
|
|
html += """ |
|
</tr> |
|
</thead> |
|
<tbody> |
|
""" |
|
|
|
|
|
for idx, row in display_df.iterrows(): |
|
row_rank = row['排名'] |
|
is_pinned = row_rank in pinned_rows if pinned_rows else False |
|
|
|
|
|
row_style = "" |
|
if is_pinned: |
|
row_style = "background-color: #e3f2fd; border-left: 4px solid #2196f3;" |
|
elif row['排名'] <= 3: |
|
row_style = "background-color: #fff3cd;" |
|
elif idx % 2 == 0: |
|
row_style = "background-color: #f8f9fa;" |
|
|
|
html += f'<tr style="{row_style}">' |
|
|
|
|
|
pin_icon = "📌" if is_pinned else "📍" |
|
html += f''' |
|
<td style="padding: 10px 8px; border: 1px solid #dee2e6; text-align: center;"> |
|
<span title="排名: {row_rank}"> |
|
{pin_icon} |
|
</span> |
|
</td> |
|
''' |
|
|
|
for col in display_df.columns: |
|
if col == 'row_id': |
|
continue |
|
|
|
cell_value = row[col] |
|
cell_style = "padding: 10px 8px; border: 1px solid #dee2e6; text-align: left;" |
|
|
|
|
|
if col == "使用链接" and cell_value != "-" and pd.notna(cell_value): |
|
cell_content = f'<a href="{cell_value}" target="_blank" style="color: #007bff; text-decoration: none;">尝试使用</a>' |
|
|
|
elif col == "平均分" and cell_value != "-": |
|
cell_style += " font-weight: bold; color: #28a745;" |
|
cell_content = str(cell_value) |
|
else: |
|
cell_content = str(cell_value) if pd.notna(cell_value) else "-" |
|
|
|
html += f'<td style="{cell_style}">{cell_content}</td>' |
|
|
|
html += '</tr>' |
|
|
|
html += """ |
|
</tbody> |
|
</table> |
|
<script> |
|
// 简化的脚本,只保留必要功能 |
|
console.log('医疗大语言模型排行榜已加载'); |
|
</script> |
|
</div> |
|
""" |
|
|
|
return html |
|
|
|
def get_multimodal_leaderboard(): |
|
"""获取医疗多模态大模型排行榜数据""" |
|
return generate_multimodal_data() |
|
|
|
def filter_llm_leaderboard(type_filter, min_score): |
|
"""根据条件筛选医疗大语言模型排行榜""" |
|
df = get_llm_leaderboard() |
|
|
|
if df.empty: |
|
return df |
|
|
|
|
|
if type_filter != "全部": |
|
df = df[df["类型"] == type_filter] |
|
|
|
|
|
if min_score > 0: |
|
|
|
df_with_score = df[df["平均分"] != "-"].copy() |
|
|
|
if not df_with_score.empty: |
|
df_with_score = df_with_score[df_with_score["平均分"] >= min_score] |
|
|
|
|
|
df = df_with_score |
|
|
|
|
|
if not df.empty: |
|
|
|
df = df.sort_values("排名", ascending=True).reset_index(drop=True) |
|
|
|
return df |
|
|
|
def filter_multimodal_leaderboard(type_filter, min_score): |
|
"""根据条件筛选医疗多模态大模型排行榜""" |
|
df = get_multimodal_leaderboard() |
|
|
|
if df.empty: |
|
return df |
|
|
|
|
|
if type_filter != "全部": |
|
df = df[df["类型"] == type_filter] |
|
|
|
|
|
if min_score > 0: |
|
|
|
df_with_score = df[df["平均分"] != "-"].copy() |
|
|
|
if not df_with_score.empty: |
|
df_with_score = df_with_score[df_with_score["平均分"] >= min_score] |
|
|
|
|
|
df = df_with_score |
|
|
|
|
|
if not df.empty: |
|
|
|
df = df.sort_values("排名", ascending=True).reset_index(drop=True) |
|
|
|
return df |
|
|
|
def generate_multimodal_html_table(df=None, sort_column=None, sort_order="desc", pinned_rows=None): |
|
"""生成医疗多模态大模型排行榜的HTML表格""" |
|
if df is None: |
|
df = get_multimodal_leaderboard() |
|
|
|
if df.empty: |
|
return "<p>暂无数据</p>" |
|
|
|
if pinned_rows is None: |
|
pinned_rows = set() |
|
|
|
|
|
if sort_column and sort_column in df.columns: |
|
|
|
if sort_column == '排名': |
|
|
|
df_for_sort = df.copy() |
|
df_for_sort['平均分_numeric'] = pd.to_numeric(df_for_sort['平均分'], errors='coerce') |
|
|
|
|
|
if sort_order == "desc": |
|
|
|
sorted_indices = df_for_sort.sort_values('平均分_numeric', ascending=False, na_position='last').index |
|
else: |
|
|
|
sorted_indices = df_for_sort.sort_values('平均分_numeric', ascending=True, na_position='last').index |
|
|
|
df = df.loc[sorted_indices].reset_index(drop=True) |
|
|
|
elif sort_column in ['平均分', 'MMMU-Med', 'VQA-RAD', 'SLAKE', 'PathVQA', 'PMC-VQA', 'OMVQA', 'MedXQA']: |
|
|
|
original_data = df.copy() |
|
|
|
|
|
df_for_sort = df.copy() |
|
df_for_sort[sort_column + '_numeric'] = pd.to_numeric(df_for_sort[sort_column], errors='coerce') |
|
|
|
|
|
if sort_order == "asc": |
|
sorted_indices = df_for_sort.sort_values(sort_column + '_numeric', ascending=True, na_position='last').index |
|
else: |
|
sorted_indices = df_for_sort.sort_values(sort_column + '_numeric', ascending=False, na_position='last').index |
|
|
|
|
|
df = original_data.loc[sorted_indices].reset_index(drop=True) |
|
else: |
|
|
|
ascending = sort_order == "asc" |
|
df = df.sort_values(sort_column, ascending=ascending, na_position='last').reset_index(drop=True) |
|
|
|
|
|
if pinned_rows: |
|
|
|
pinned_df = df[df['排名'].isin(pinned_rows)].copy() |
|
unpinned_df = df[~df['排名'].isin(pinned_rows)].copy() |
|
|
|
|
|
if not pinned_df.empty: |
|
pinned_df = pinned_df.sort_values('排名', ascending=True) |
|
|
|
|
|
|
|
|
|
|
|
if not pinned_df.empty: |
|
display_df = pd.concat([pinned_df, unpinned_df], ignore_index=True) |
|
else: |
|
display_df = unpinned_df |
|
else: |
|
|
|
display_df = df.reset_index(drop=True) |
|
|
|
|
|
display_df['row_id'] = display_df.index |
|
|
|
|
|
html = """ |
|
<div style="overflow-x: auto; width: 100%;"> |
|
<style> |
|
.sort-btn { |
|
background: none; |
|
border: none; |
|
cursor: pointer; |
|
margin-left: 5px; |
|
font-size: 12px; |
|
color: #007bff; |
|
padding: 2px 4px; |
|
border-radius: 3px; |
|
} |
|
.sort-btn:hover { |
|
background-color: #e9ecef; |
|
} |
|
.sort-btn:active { |
|
background-color: #dee2e6; |
|
} |
|
.pin-btn { |
|
background: none; |
|
border: none; |
|
cursor: pointer; |
|
font-size: 16px; |
|
padding: 2px 4px; |
|
margin-right: 8px; |
|
border-radius: 3px; |
|
} |
|
.pin-btn:hover { |
|
background-color: #e9ecef; |
|
} |
|
.pinned-row { |
|
background-color: #e3f2fd !important; |
|
border-left: 4px solid #2196f3 !important; |
|
} |
|
</style> |
|
<table style="width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 14px;"> |
|
<thead> |
|
<tr style="background-color: #f8f9fa; border-bottom: 2px solid #dee2e6;"> |
|
""" |
|
|
|
|
|
html += '<th style="padding: 12px 8px; text-align: center; border: 1px solid #dee2e6; font-weight: bold; width: 50px;">📌</th>' |
|
|
|
for col in display_df.columns: |
|
if col == 'row_id': |
|
continue |
|
html += f''' |
|
<th style="padding: 12px 8px; text-align: left; border: 1px solid #dee2e6; font-weight: bold;"> |
|
{col} |
|
</th> |
|
''' |
|
|
|
html += """ |
|
</tr> |
|
</thead> |
|
<tbody> |
|
""" |
|
|
|
|
|
for idx, row in display_df.iterrows(): |
|
row_rank = row['排名'] |
|
is_pinned = row_rank in pinned_rows if pinned_rows else False |
|
|
|
|
|
row_style = "" |
|
if is_pinned: |
|
row_style = "background-color: #e3f2fd; border-left: 4px solid #2196f3;" |
|
elif row['排名'] <= 3: |
|
row_style = "background-color: #fff3cd;" |
|
elif idx % 2 == 0: |
|
row_style = "background-color: #f8f9fa;" |
|
|
|
html += f'<tr style="{row_style}">' |
|
|
|
|
|
pin_icon = "📌" if is_pinned else "📍" |
|
html += f''' |
|
<td style="padding: 10px 8px; border: 1px solid #dee2e6; text-align: center;"> |
|
<span title="排名: {row_rank}"> |
|
{pin_icon} |
|
</span> |
|
</td> |
|
''' |
|
|
|
for col in display_df.columns: |
|
if col == 'row_id': |
|
continue |
|
|
|
cell_value = row[col] |
|
cell_style = "padding: 10px 8px; border: 1px solid #dee2e6; text-align: left;" |
|
|
|
|
|
if col == "使用链接" and cell_value != "-" and pd.notna(cell_value): |
|
cell_content = f'<a href="{cell_value}" target="_blank" style="color: #007bff; text-decoration: none;">尝试使用</a>' |
|
|
|
elif col == "平均分" and cell_value != "-": |
|
cell_style += " font-weight: bold; color: #28a745;" |
|
cell_content = str(cell_value) |
|
else: |
|
cell_content = str(cell_value) if pd.notna(cell_value) else "-" |
|
|
|
html += f'<td style="{cell_style}">{cell_content}</td>' |
|
|
|
html += '</tr>' |
|
|
|
html += """ |
|
</tbody> |
|
</table> |
|
<script> |
|
// 简化的脚本,只保留必要功能 |
|
console.log('医疗多模态大模型排行榜已加载'); |
|
</script> |
|
</div> |
|
""" |
|
|
|
return html |
|
|
|
|
|
with gr.Blocks(title="医疗大模型排行榜", theme=gr.themes.Soft(), css=""" |
|
.responsive-table { |
|
width: 100%; |
|
overflow-x: auto; |
|
} |
|
.responsive-table table { |
|
width: 100%; |
|
min-width: 800px; |
|
} |
|
/* 确保表格内容不会被截断 */ |
|
.responsive-table td { |
|
white-space: nowrap; |
|
overflow: hidden; |
|
text-overflow: ellipsis; |
|
} |
|
/* 平均分列样式 */ |
|
.responsive-table td:nth-child(3) { |
|
font-weight: bold; |
|
} |
|
""") as demo: |
|
gr.Markdown("# 🤖 医疗大模型排行榜") |
|
gr.Markdown("欢迎来到 RS Medical LLM Leaderboard 排行榜!这里展示了医疗领域大语言模型和医疗多模态模型的性能排名。我们是一个中立的评估机构,旨在将模型性能公平的进行比较。我们将在未来推出医版 Arena 平台。") |
|
|
|
with gr.Tabs(): |
|
|
|
with gr.TabItem("💬 医疗大语言模型排行榜"): |
|
|
|
with gr.Row(): |
|
llm_type_filter = gr.Dropdown( |
|
choices=["全部", "开源", "商业"], |
|
value="全部", |
|
label="模型类型", |
|
scale=1 |
|
) |
|
llm_min_score = gr.Slider( |
|
minimum=0, |
|
maximum=80, |
|
value=0, |
|
step=5, |
|
label="最低平均分", |
|
scale=2 |
|
) |
|
llm_refresh_btn = gr.Button("🔄 刷新数据", variant="primary", scale=1) |
|
|
|
|
|
with gr.Row(): |
|
llm_sort_column = gr.Dropdown( |
|
choices=["排名", "模型名称", "平均分", "MMMU-Med", "VQA-RAD", "SLAKE", "PathVQA", "PMC-VQA", "OMVQA", "MedXQA", "最后更新", "类型"], |
|
value="排名", |
|
label="排序列", |
|
scale=2 |
|
) |
|
llm_sort_order = gr.Radio( |
|
choices=[("升序 ↑", "asc"), ("降序 ↓", "desc")], |
|
value="desc", |
|
label="排序方式", |
|
scale=1 |
|
) |
|
with gr.Column(scale=1): |
|
llm_default_sort_btn = gr.Button("↩️ 默认排序", variant="primary", scale=1) |
|
|
|
|
|
with gr.Row(): |
|
llm_pin_input = gr.Textbox( |
|
label="置顶行号(用逗号分隔多个行号,如:1,3,5)", |
|
placeholder="输入要置顶的行号", |
|
scale=2 |
|
) |
|
with gr.Column(scale=1): |
|
llm_pin_btn = gr.Button("📌 应用置顶", variant="primary", scale=1) |
|
llm_clear_pin_btn = gr.Button("🗑️ 清除置顶", variant="primary", scale=1) |
|
|
|
|
|
llm_pinned_state = gr.State(value=set()) |
|
|
|
|
|
llm_leaderboard_html = gr.HTML( |
|
value=generate_llm_html_table(pinned_rows=set()), |
|
label="医疗大语言模型排行榜" |
|
) |
|
|
|
|
|
with gr.TabItem("👁️ 医疗多模态大模型排行榜"): |
|
|
|
with gr.Row(): |
|
multimodal_type_filter = gr.Dropdown( |
|
choices=["全部", "开源", "商业"], |
|
value="全部", |
|
label="模型类型", |
|
scale=1 |
|
) |
|
multimodal_min_score = gr.Slider( |
|
minimum=0, |
|
maximum=80, |
|
value=0, |
|
step=5, |
|
label="最低平均分", |
|
scale=2 |
|
) |
|
multimodal_refresh_btn = gr.Button("🔄 刷新数据", variant="primary", scale=1) |
|
|
|
|
|
with gr.Row(): |
|
sort_column = gr.Dropdown( |
|
choices=["排名", "模型名称", "平均分", "MMMU-Med", "VQA-RAD", "SLAKE", "PathVQA", "PMC-VQA", "OMVQA", "MedXQA", "最后更新", "类型"], |
|
value="排名", |
|
label="排序列", |
|
scale=2 |
|
) |
|
sort_order = gr.Radio( |
|
choices=[("升序 ↑", "asc"), ("降序 ↓", "desc")], |
|
value="desc", |
|
label="排序方式", |
|
scale=1 |
|
) |
|
with gr.Column(scale=1): |
|
|
|
default_sort_btn = gr.Button("↩️ 默认排序", variant="primary", scale=1) |
|
|
|
|
|
with gr.Row(): |
|
pin_input = gr.Textbox( |
|
label="置顶行号(用逗号分隔多个行号,如:1,3,5)", |
|
placeholder="输入要置顶的行号", |
|
scale=2 |
|
) |
|
with gr.Column(scale=1): |
|
pin_btn = gr.Button("📌 应用置顶", variant="primary", scale=1) |
|
clear_pin_btn = gr.Button("🗑️ 清除置顶", variant="primary", scale=1) |
|
|
|
|
|
pinned_state = gr.State(value=set()) |
|
|
|
|
|
multimodal_leaderboard_html = gr.HTML( |
|
value=generate_multimodal_html_table(pinned_rows=set()), |
|
label="医疗多模态大模型排行榜" |
|
) |
|
|
|
|
|
def update_llm_leaderboard_html(type_filter, min_score, sort_col=None, sort_ord="desc", pinned_rows=None): |
|
if pinned_rows is None: |
|
pinned_rows = set() |
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
return generate_llm_html_table(filtered_df, sort_col, sort_ord, pinned_rows) |
|
|
|
def sort_llm_table(type_filter, min_score, sort_col, sort_ord, pinned_rows): |
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
return generate_llm_html_table(filtered_df, sort_col, sort_ord, pinned_rows) |
|
|
|
def default_sort_llm_table(type_filter, min_score, pinned_rows): |
|
"""恢复默认排序(按平均分排名)""" |
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
html_table = generate_llm_html_table(filtered_df, None, "desc", pinned_rows) |
|
|
|
return html_table, "排名", "desc" |
|
|
|
def apply_llm_pin(pin_input_text, type_filter, min_score, sort_col, sort_ord, current_pinned): |
|
"""应用置顶设置""" |
|
try: |
|
if pin_input_text.strip(): |
|
|
|
pin_numbers = [int(x.strip()) for x in pin_input_text.split(',') if x.strip()] |
|
|
|
new_pinned = set(n for n in pin_numbers if n > 0) |
|
else: |
|
new_pinned = set() |
|
|
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
html_table = generate_llm_html_table(filtered_df, sort_col, sort_ord, new_pinned) |
|
return html_table, new_pinned |
|
except ValueError: |
|
|
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
html_table = generate_llm_html_table(filtered_df, sort_col, sort_ord, current_pinned) |
|
return html_table, current_pinned |
|
|
|
def clear_llm_pin(type_filter, min_score, sort_col, sort_ord): |
|
"""清除所有置顶""" |
|
filtered_df = filter_llm_leaderboard(type_filter, min_score) |
|
html_table = generate_llm_html_table(filtered_df, sort_col, sort_ord, set()) |
|
return html_table, set(), "" |
|
|
|
def update_multimodal_leaderboard_html(type_filter, min_score, sort_col=None, sort_ord="desc", pinned_rows=None): |
|
if pinned_rows is None: |
|
pinned_rows = set() |
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
return generate_multimodal_html_table(filtered_df, sort_col, sort_ord, pinned_rows) |
|
|
|
def sort_multimodal_table(type_filter, min_score, sort_col, sort_ord, pinned_rows): |
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
return generate_multimodal_html_table(filtered_df, sort_col, sort_ord, pinned_rows) |
|
|
|
def default_sort_multimodal_table(type_filter, min_score, pinned_rows): |
|
"""恢复默认排序(按平均分排名)""" |
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
html_table = generate_multimodal_html_table(filtered_df, None, "desc", pinned_rows) |
|
|
|
return html_table, "排名", "desc" |
|
|
|
def apply_pin(pin_input_text, type_filter, min_score, sort_col, sort_ord, current_pinned): |
|
"""应用置顶设置""" |
|
try: |
|
if pin_input_text.strip(): |
|
|
|
pin_numbers = [int(x.strip()) for x in pin_input_text.split(',') if x.strip()] |
|
|
|
new_pinned = set(n for n in pin_numbers if n > 0) |
|
else: |
|
new_pinned = set() |
|
|
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
html_table = generate_multimodal_html_table(filtered_df, sort_col, sort_ord, new_pinned) |
|
return html_table, new_pinned |
|
except ValueError: |
|
|
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
html_table = generate_multimodal_html_table(filtered_df, sort_col, sort_ord, current_pinned) |
|
return html_table, current_pinned |
|
|
|
def clear_pin(type_filter, min_score, sort_col, sort_ord): |
|
"""清除所有置顶""" |
|
filtered_df = filter_multimodal_leaderboard(type_filter, min_score) |
|
html_table = generate_multimodal_html_table(filtered_df, sort_col, sort_ord, set()) |
|
return html_table, set(), "" |
|
|
|
|
|
llm_type_filter.change( |
|
fn=sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=llm_leaderboard_html |
|
) |
|
|
|
llm_min_score.change( |
|
fn=sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=llm_leaderboard_html |
|
) |
|
|
|
llm_refresh_btn.click( |
|
fn=sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=llm_leaderboard_html |
|
) |
|
|
|
|
|
llm_sort_column.change( |
|
fn=sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=llm_leaderboard_html |
|
) |
|
|
|
llm_sort_order.change( |
|
fn=sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=llm_leaderboard_html |
|
) |
|
|
|
|
|
llm_default_sort_btn.click( |
|
fn=default_sort_llm_table, |
|
inputs=[llm_type_filter, llm_min_score, llm_pinned_state], |
|
outputs=[llm_leaderboard_html, llm_sort_column, llm_sort_order] |
|
) |
|
|
|
|
|
llm_pin_btn.click( |
|
fn=apply_llm_pin, |
|
inputs=[llm_pin_input, llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order, llm_pinned_state], |
|
outputs=[llm_leaderboard_html, llm_pinned_state] |
|
) |
|
|
|
llm_clear_pin_btn.click( |
|
fn=clear_llm_pin, |
|
inputs=[llm_type_filter, llm_min_score, llm_sort_column, llm_sort_order], |
|
outputs=[llm_leaderboard_html, llm_pinned_state, llm_pin_input] |
|
) |
|
|
|
|
|
multimodal_type_filter.change( |
|
fn=sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=multimodal_leaderboard_html |
|
) |
|
|
|
multimodal_min_score.change( |
|
fn=sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=multimodal_leaderboard_html |
|
) |
|
|
|
multimodal_refresh_btn.click( |
|
fn=sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=multimodal_leaderboard_html |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort_column.change( |
|
fn=sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=multimodal_leaderboard_html |
|
) |
|
|
|
sort_order.change( |
|
fn=sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=multimodal_leaderboard_html |
|
) |
|
|
|
|
|
default_sort_btn.click( |
|
fn=default_sort_multimodal_table, |
|
inputs=[multimodal_type_filter, multimodal_min_score, pinned_state], |
|
outputs=[multimodal_leaderboard_html, sort_column, sort_order] |
|
) |
|
|
|
|
|
pin_btn.click( |
|
fn=apply_pin, |
|
inputs=[pin_input, multimodal_type_filter, multimodal_min_score, sort_column, sort_order, pinned_state], |
|
outputs=[multimodal_leaderboard_html, pinned_state] |
|
) |
|
|
|
clear_pin_btn.click( |
|
fn=clear_pin, |
|
inputs=[multimodal_type_filter, multimodal_min_score, sort_column, sort_order], |
|
outputs=[multimodal_leaderboard_html, pinned_state, pin_input] |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch( |
|
|
|
|
|
share=False, |
|
show_error=True |
|
) |
|
|