File size: 3,837 Bytes
5f3eeaf
 
0b41ab5
 
 
f6590f0
 
01809c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f3eeaf
 
 
 
 
 
0b41ab5
5f3eeaf
 
 
 
01809c9
 
0b41ab5
 
 
08a24e4
 
f06ca02
17aa841
 
 
 
0b41ab5
01809c9
 
 
 
 
 
 
 
 
 
 
 
 
 
0b41ab5
 
08a24e4
6f65006
0b41ab5
 
6f65006
01809c9
 
 
 
 
 
0b41ab5
 
6f65006
0b41ab5
 
 
 
6f65006
0b41ab5
 
 
214ffa6
c52847e
6f65006
0b41ab5
 
6f65006
0b41ab5
6f65006
214ffa6
6f65006
5f3eeaf
6f65006
214ffa6
6f65006
0b41ab5
 
 
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
import json

import gradio as gr
import pandas as pd

from pages.summarization_playground import custom_css

css = '''
.tooltip-wrapper {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip-wrapper .tooltip {
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip-wrapper:hover .tooltip {
    visibility: visible;
    opacity: 1;
}
'''

with open("prompt/prompt.json", "r") as file:
    json_data = file.read()
    prompts = json.loads(json_data)# Sample data for the leaderboard

winning_rate = [prompt['metric']['winning_number'] for prompt in prompts]
winning_rate = [num / sum(winning_rate) for num in winning_rate]
data = {
    'Rank': [i+1 for i in range(len(prompts))],
    'Methods': [prompt['id'] for prompt in prompts],
    'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
    'Winning Rate': winning_rate,
    'Authors': [prompt['author'] for prompt in prompts],
    'Prompts': [prompt['prompt'] for prompt in prompts]
}

df = pd.DataFrame(data)
df.sort_values(by='Rouge Score', ascending=False, inplace=True, ignore_index=True)
df['Rank'] = range(1, len(df) + 1)

# Define a list of medal emojis
medals = ['πŸ…', 'πŸ₯ˆ', 'πŸ₯‰']
for i in range(3):
    df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"


def create_html_with_tooltip(text, tooltip):
    return f'''
    <div class="tooltip-wrapper">
        {text}
        <span class="tooltip">{tooltip}</span>
    </div>
    '''

def show_tooltip():
    text_with_tooltip = create_html_with_tooltip("Hover over me", "This is a tooltip!")
    return text_with_tooltip


def update_leaderboard(sort_by):
    # In a real implementation, this would filter the data based on the category
    sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)

    # Update ranks based on new sorting
    sorted_df['Rank'] = range(1, len(sorted_df) + 1)

    # Create hover effect for Methods column
    sorted_df['Methods'] = sorted_df.apply(lambda row: create_html_with_tooltip(row['Methods'], row['Prompts']), axis=1)

    # Drop the 'Prompts' column as we don't want to display it directly
    sorted_df = sorted_df.drop(columns=['Prompts'])

    # Convert DataFrame to HTML with clickable headers for sorting
    html = sorted_df.to_html(index=False, escape=False)

    # Add sorting links to column headers
    for column in sorted_df.columns:
        html = html.replace(f'<th>{column}</th>', 
                            f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')

    return html

def create_leaderboard():
    with gr.Blocks(css=custom_css) 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. We use the DATASET_NAME_PLACEHOLDER dataset to generate summaries with MODEL_NAME_PLACEHOLDER. These summaries are then evaluated by STRONGER_MODEL_NAME_PLACEHOLDER using the METRIC1_PLACEHOLDER and METRIC2_PLACEHOLDER metrics")

        sort_by = gr.Dropdown(list(df.columns), label="Sort by", value="Rouge Score")

        gr.Markdown("**Performance**\n\n**methods**: 5,   **questions**: 15")

        leaderboard = gr.HTML(update_leaderboard("Rouge Score"), elem_id="leaderboard")

        sort_by.change(update_leaderboard, inputs=[sort_by], outputs=[leaderboard])

    return demo