kz209 commited on
Commit
d7f5c38
β€’
1 Parent(s): e233ec3
pages/leaderboard.py CHANGED
@@ -1,49 +1,11 @@
 
 
1
  import json
2
-
3
  import gradio as gr
4
- import pandas as pd
5
 
6
- from pages.summarization_playground import custom_css
7
-
8
- css = '''
9
- .tooltip-wrapper {
10
- position: relative;
11
- display: inline-block;
12
- border-bottom: 1px dotted black;
13
- }
14
-
15
- .tooltip-wrapper .tooltip {
16
- visibility: hidden;
17
- width: 300px; /* Increased width */
18
- background-color: black;
19
- color: #fff;
20
- text-align: left; /* Changed to left align */
21
- border-radius: 6px;
22
- padding: 5px;
23
- position: absolute;
24
- z-index: 1;
25
- bottom: 125%;
26
- left: 50%;
27
- margin-left: -150px; /* Half of the width */
28
- opacity: 0;
29
- transition: opacity 0.3s;
30
- white-space: pre-wrap; /* Allow text wrapping */
31
- word-wrap: break-word; /* Break long words if necessary */
32
- }
33
-
34
- .tooltip-wrapper:hover .tooltip {
35
- visibility: visible;
36
- opacity: 1;
37
- }
38
- '''
39
-
40
- def create_html_with_tooltip(text, tooltip):
41
- return f'''
42
- <div class="tooltip-wrapper">
43
- {text}
44
- <span class="tooltip">{tooltip}</span>
45
- </div>
46
- '''
47
 
48
  with open("prompt/prompt.json", "r") as file:
49
  json_data = file.read()
@@ -53,11 +15,10 @@ winning_rate = [prompt['metric']['winning_number'] for prompt in prompts]
53
  winning_rate = [num / sum(winning_rate) for num in winning_rate]
54
  data = {
55
  'Rank': [i+1 for i in range(len(prompts))],
56
- 'Methods': [create_html_with_tooltip(prompt['id'], prompt['prompt']) for prompt in prompts],
57
  'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
58
  'Winning Rate': winning_rate,
59
  'Authors': [prompt['author'] for prompt in prompts],
60
- 'Prompts': [prompt['prompt'] for prompt in prompts]
61
  }
62
 
63
  df = pd.DataFrame(data)
@@ -69,35 +30,59 @@ medals = ['πŸ…', 'πŸ₯ˆ', 'πŸ₯‰']
69
  for i in range(3):
70
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
71
 
 
 
 
 
72
  def update_leaderboard(sort_by):
73
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
74
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
75
-
76
  # Convert DataFrame to HTML with clickable headers for sorting and without escaping
77
- html = sorted_df.to_html(index=False, escape=False)
78
-
79
  # Add sorting links to column headers
80
  for column in sorted_df.columns:
81
- html = html.replace(f'<th>{column}</th>',
82
  f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
83
-
84
- return html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  def create_leaderboard():
87
- with gr.Blocks(css=css) as demo:
 
 
88
  gr.Markdown("# πŸ† Summarization Arena Leaderboard")
89
-
90
  with gr.Row():
91
  gr.Markdown("[Blog](placeholder) | [GitHub](placeholder) | [Paper](placeholder) | [Dataset](placeholder) | [Twitter](placeholder) | [Discord](placeholder)")
92
-
93
  gr.Markdown("Welcome to our open platform for evaluating LLM summarization capabilities. We use the DATASET_NAME_PLACEHOLDER dataset to generate summaries with Qwen2-1.5b. These summaries are then evaluated by Rouge and Winning Rate from the arena")
94
-
95
  sort_by = gr.Dropdown(list(df.columns), label="Sort by", value="Rouge Score")
96
-
97
  gr.Markdown("**Performance**\n\n**methods**: 5, **questions**: 15")
98
-
99
  leaderboard = gr.HTML(update_leaderboard("Rouge Score"), elem_id="leaderboard")
100
-
101
  sort_by.change(update_leaderboard, inputs=[sort_by], outputs=[leaderboard])
 
 
102
 
103
- return demo
 
 
 
1
+ import pandas as pd
2
+ import html
3
  import json
 
4
  import gradio as gr
 
5
 
6
+ def create_html_with_tooltip(id, prompt):
7
+ escaped_prompt = html.escape(prompt.replace("\n", "<br />"))
8
+ return f'<span class="tooltip" data-id="{id}" data-prompt="{escaped_prompt}">{id}</span>'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  with open("prompt/prompt.json", "r") as file:
11
  json_data = file.read()
 
15
  winning_rate = [num / sum(winning_rate) for num in winning_rate]
16
  data = {
17
  'Rank': [i+1 for i in range(len(prompts))],
18
+ 'Methods': [create_html_with_tooltip(prompt['id'], prompt['prompt'].replace("\n","<br />")) for prompt in prompts],
19
  'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
20
  'Winning Rate': winning_rate,
21
  'Authors': [prompt['author'] for prompt in prompts],
 
22
  }
23
 
24
  df = pd.DataFrame(data)
 
30
  for i in range(3):
31
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
32
 
33
+ def create_html_with_tooltip(id, prompt):
34
+ escaped_prompt = html.escape(prompt.replace("\n", "<br />"))
35
+ return f'<span class="tooltip" data-id="{id}" data-prompt="{escaped_prompt}">{id}</span>'
36
+
37
  def update_leaderboard(sort_by):
38
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
39
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
40
+
41
  # Convert DataFrame to HTML with clickable headers for sorting and without escaping
42
+ table_html = sorted_df.to_html(index=False, escape=False)
43
+
44
  # Add sorting links to column headers
45
  for column in sorted_df.columns:
46
+ table_html = table_html.replace(f'<th>{column}</th>',
47
  f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
48
+
49
+ # Load the HTML template
50
+ with open('pages/leaderboard_template.html', 'r') as file:
51
+ template = file.read()
52
+
53
+ # Create the sortBy function in JavaScript
54
+ sort_by_function = f"""
55
+ function sortBy(column) {{
56
+ const gradioEl = document.querySelector('gradio-app');
57
+ const dropdown = gradioEl.querySelector('select');
58
+ dropdown.value = column;
59
+ dropdown.dispatchEvent(new Event('change'));
60
+ }}
61
+ """
62
+
63
+ # Insert the table HTML and sortBy function into the template
64
+ full_html = template.replace('<div id="leaderboard-container"></div>',
65
+ f'<div id="leaderboard-container">{table_html}</div>')
66
+ full_html = full_html.replace('// This function will be implemented in Python and injected here',
67
+ sort_by_function)
68
+
69
+ return full_html
70
 
71
  def create_leaderboard():
72
+ with gr.Blocks(css="""
73
+ .tooltip { cursor: pointer; color: blue; text-decoration: underline; }
74
+ """) as demo:
75
  gr.Markdown("# πŸ† Summarization Arena Leaderboard")
 
76
  with gr.Row():
77
  gr.Markdown("[Blog](placeholder) | [GitHub](placeholder) | [Paper](placeholder) | [Dataset](placeholder) | [Twitter](placeholder) | [Discord](placeholder)")
 
78
  gr.Markdown("Welcome to our open platform for evaluating LLM summarization capabilities. We use the DATASET_NAME_PLACEHOLDER dataset to generate summaries with Qwen2-1.5b. These summaries are then evaluated by Rouge and Winning Rate from the arena")
 
79
  sort_by = gr.Dropdown(list(df.columns), label="Sort by", value="Rouge Score")
 
80
  gr.Markdown("**Performance**\n\n**methods**: 5, **questions**: 15")
 
81
  leaderboard = gr.HTML(update_leaderboard("Rouge Score"), elem_id="leaderboard")
 
82
  sort_by.change(update_leaderboard, inputs=[sort_by], outputs=[leaderboard])
83
+ return demo
84
+
85
 
86
+ if __name__ == "__main__":
87
+ demo = create_leaderboard()
88
+ demo.launch()
pages/leaderboard_template.html ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Summarization Arena Leaderboard</title>
7
+ <style>
8
+ .tooltip {
9
+ cursor: pointer;
10
+ color: blue;
11
+ text-decoration: underline;
12
+ }
13
+ table {
14
+ border-collapse: collapse;
15
+ width: 100%;
16
+ }
17
+ th, td {
18
+ border: 1px solid #ddd;
19
+ padding: 8px;
20
+ text-align: left;
21
+ }
22
+ th {
23
+ background-color: #f2f2f2;
24
+ }
25
+ #prompt-display {
26
+ display: none;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body>
31
+ <div id="leaderboard-container"></div>
32
+ <div id="prompt-display">
33
+ <h2 id="prompt-title"></h2>
34
+ <pre id="prompt-content"></pre>
35
+ <button onclick="showLeaderboard()">Back to Leaderboard</button>
36
+ </div>
37
+
38
+ <script>
39
+ function sortBy(column) {
40
+ // This function will be implemented in Python and injected here
41
+ }
42
+
43
+ function showPrompt(id, prompt) {
44
+ document.getElementById('leaderboard-container').style.display = 'none';
45
+ document.getElementById('prompt-display').style.display = 'block';
46
+ document.getElementById('prompt-title').textContent = 'Prompt for ' + id;
47
+ document.getElementById('prompt-content').textContent = prompt;
48
+ }
49
+
50
+ function showLeaderboard() {
51
+ document.getElementById('leaderboard-container').style.display = 'block';
52
+ document.getElementById('prompt-display').style.display = 'none';
53
+ }
54
+
55
+ document.addEventListener('DOMContentLoaded', function() {
56
+ const leaderboardContainer = document.getElementById('leaderboard-container');
57
+ leaderboardContainer.addEventListener('click', function(event) {
58
+ if (event.target.classList.contains('tooltip')) {
59
+ const id = event.target.getAttribute('data-id');
60
+ const prompt = event.target.getAttribute('data-prompt');
61
+ showPrompt(id, prompt);
62
+ }
63
+ });
64
+ });
65
+ </script>
66
+ </body>
67
+ </html>