Spaces:
Sleeping
Sleeping
File size: 3,064 Bytes
d7f5c38 5f3eeaf eebe34f 0b41ab5 eebe34f e233ec3 eebe34f 5f3eeaf eebe34f 5f3eeaf eebe34f 5f3eeaf 07b83f1 0b41ab5 5f3eeaf eebe34f 5f3eeaf 01809c9 0b41ab5 eebe34f 0b41ab5 08a24e4 f06ca02 eebe34f 17aa841 0b41ab5 eebe34f 0b41ab5 08a24e4 0b41ab5 eebe34f d7f5c38 eebe34f e233ec3 0b41ab5 d7f5c38 eebe34f 0b41ab5 eebe34f 0b41ab5 d7f5c38 eebe34f d7f5c38 c52847e 0b41ab5 eebe34f 214ffa6 eebe34f 214ffa6 eebe34f d7f5c38 eebe34f 0b41ab5 eebe34f d7f5c38 eebe34f |
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 |
import html
import json
import pandas as pd
import gradio as gr
# Function to create HTML tooltips
def create_html_with_tooltip(id, base_url):
return f'<a href="{base_url}"target="_blank">{id}</a>'
# Load prompts from JSON
with open("prompt/prompt.json", "r") as file:
json_data = file.read()
prompts = json.loads(json_data)
# Prepare leaderboard data
winning_rate = [prompt['metric']['winning_number'] for prompt in prompts]
winning_rate = [round(num / sum(winning_rate), 4)for num in winning_rate]
data = {
'Rank': [i+1 for i in range(len(prompts))],
'Methods': [create_html_with_tooltip(prompt['id'], prompt['url']) for prompt in prompts],
'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
'Winning Rate': winning_rate,
'Authors': [prompt['author'] for prompt in prompts],
}
# Create DataFrame and sort by Rouge Score
df = pd.DataFrame(data)
df.sort_values(by='Rouge Score', ascending=False, inplace=True, ignore_index=True)
df['Rank'] = range(1, len(df) + 1)
# Assign medals for top 3 authors
medals = ['π
', 'π₯', 'π₯']
for i in range(3):
df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
# Function to update the leaderboard
def update_leaderboard(sort_by):
sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
sorted_df['Rank'] = range(1, len(sorted_df) + 1)
# Convert DataFrame to HTML with clickable headers for sorting
table_html = sorted_df.to_html(index=False, escape=False)
# Add sorting links to column headers
for column in sorted_df.columns:
table_html = table_html.replace(f'<th>{column}</th>',
f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
return table_html
# Define Gradio interface
def create_leaderboard():
with gr.Blocks(css="""
.tooltip { cursor: pointer; color: blue; text-decoration: underline; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
#prompt-display { display: none; }
""") as demo:
gr.Markdown("# π Summarization Arena Leaderboard")
with gr.Row():
gr.Markdown("[Blog](placeholder) | [GitHub](placeholder) | [Paper](placeholder) | [Dataset](placeholder) | [Twitter](placeholder) | [Discord](placeholder)")
gr.Markdown("Welcome to our open platform for evaluating LLM summarization capabilities.")
# Dropdown for sorting
sort_by = gr.Dropdown(list(df.columns), label="Sort by", value="Rouge Score")
# Display the leaderboard
leaderboard = gr.HTML(update_leaderboard("Rouge Score"), elem_id="leaderboard")
# Change sorting when dropdown is changed
sort_by.change(fn=lambda sort: update_leaderboard(sort), inputs=sort_by, outputs=leaderboard)
return demo
# Launch Gradio interface
if __name__ == "__main__":
demo = create_leaderboard()
demo.launch(debug=True)
|