kz209 commited on
Commit
01809c9
β€’
1 Parent(s): 08a24e4
Files changed (1) hide show
  1. pages/leaderboard.py +52 -1
pages/leaderboard.py CHANGED
@@ -5,6 +5,36 @@ import pandas as pd
5
 
6
  from pages.summarization_playground import custom_css
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  with open("prompt/prompt.json", "r") as file:
9
  json_data = file.read()
10
  prompts = json.loads(json_data)# Sample data for the leaderboard
@@ -16,7 +46,8 @@ data = {
16
  'Methods': [prompt['id'] for prompt in prompts],
17
  'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
18
  'Winning Rate': winning_rate,
19
- 'Authors': [prompt['author'] for prompt in prompts]
 
20
  }
21
 
22
  df = pd.DataFrame(data)
@@ -28,6 +59,20 @@ medals = ['πŸ…', 'πŸ₯ˆ', 'πŸ₯‰']
28
  for i in range(3):
29
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  def update_leaderboard(sort_by):
32
  # In a real implementation, this would filter the data based on the category
33
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
@@ -35,6 +80,12 @@ def update_leaderboard(sort_by):
35
  # Update ranks based on new sorting
36
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
37
 
 
 
 
 
 
 
38
  # Convert DataFrame to HTML with clickable headers for sorting
39
  html = sorted_df.to_html(index=False, escape=False)
40
 
 
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: 120px;
18
+ background-color: black;
19
+ color: #fff;
20
+ text-align: center;
21
+ border-radius: 6px;
22
+ padding: 5px 0;
23
+ position: absolute;
24
+ z-index: 1;
25
+ bottom: 125%;
26
+ left: 50%;
27
+ margin-left: -60px;
28
+ opacity: 0;
29
+ transition: opacity 0.3s;
30
+ }
31
+
32
+ .tooltip-wrapper:hover .tooltip {
33
+ visibility: visible;
34
+ opacity: 1;
35
+ }
36
+ '''
37
+
38
  with open("prompt/prompt.json", "r") as file:
39
  json_data = file.read()
40
  prompts = json.loads(json_data)# Sample data for the leaderboard
 
46
  'Methods': [prompt['id'] for prompt in prompts],
47
  'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
48
  'Winning Rate': winning_rate,
49
+ 'Authors': [prompt['author'] for prompt in prompts],
50
+ 'Prompts': [prompt['prompt'] for prompt in prompts]
51
  }
52
 
53
  df = pd.DataFrame(data)
 
59
  for i in range(3):
60
  df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
61
 
62
+
63
+ def create_html_with_tooltip(text, tooltip):
64
+ return f'''
65
+ <div class="tooltip-wrapper">
66
+ {text}
67
+ <span class="tooltip">{tooltip}</span>
68
+ </div>
69
+ '''
70
+
71
+ def show_tooltip():
72
+ text_with_tooltip = create_html_with_tooltip("Hover over me", "This is a tooltip!")
73
+ return text_with_tooltip
74
+
75
+
76
  def update_leaderboard(sort_by):
77
  # In a real implementation, this would filter the data based on the category
78
  sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
 
80
  # Update ranks based on new sorting
81
  sorted_df['Rank'] = range(1, len(sorted_df) + 1)
82
 
83
+ # Create hover effect for Methods column
84
+ sorted_df['Methods'] = sorted_df.apply(lambda row: create_html_with_tooltip(row['Methods'], row['Prompts']), axis=1)
85
+
86
+ # Drop the 'Prompts' column as we don't want to display it directly
87
+ sorted_df = sorted_df.drop(columns=['Prompts'])
88
+
89
  # Convert DataFrame to HTML with clickable headers for sorting
90
  html = sorted_df.to_html(index=False, escape=False)
91