Spaces:
Sleeping
Sleeping
kz209
commited on
Commit
β’
e233ec3
1
Parent(s):
64def17
update
Browse files- pages/leaderboard.py +16 -21
pages/leaderboard.py
CHANGED
@@ -14,21 +14,21 @@ css = '''
|
|
14 |
|
15 |
.tooltip-wrapper .tooltip {
|
16 |
visibility: hidden;
|
17 |
-
width: 300px;
|
18 |
background-color: black;
|
19 |
color: #fff;
|
20 |
-
text-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;
|
28 |
opacity: 0;
|
29 |
transition: opacity 0.3s;
|
30 |
-
white-space: pre-wrap;
|
31 |
-
word-wrap: break-word;
|
32 |
}
|
33 |
|
34 |
.tooltip-wrapper:hover .tooltip {
|
@@ -37,6 +37,14 @@ css = '''
|
|
37 |
}
|
38 |
'''
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
with open("prompt/prompt.json", "r") as file:
|
41 |
json_data = file.read()
|
42 |
prompts = json.loads(json_data)# Sample data for the leaderboard
|
@@ -45,7 +53,7 @@ winning_rate = [prompt['metric']['winning_number'] for prompt in prompts]
|
|
45 |
winning_rate = [num / sum(winning_rate) for num in winning_rate]
|
46 |
data = {
|
47 |
'Rank': [i+1 for i in range(len(prompts))],
|
48 |
-
'Methods': [prompt['id'] for prompt in prompts],
|
49 |
'Rouge Score': [prompt['metric']['Rouge'] for prompt in prompts],
|
50 |
'Winning Rate': winning_rate,
|
51 |
'Authors': [prompt['author'] for prompt in prompts],
|
@@ -61,27 +69,14 @@ medals = ['π
', 'π₯', 'π₯']
|
|
61 |
for i in range(3):
|
62 |
df.loc[i, 'Authors'] = f"{medals[i]} {df.loc[i, 'Authors']}"
|
63 |
|
64 |
-
|
65 |
-
def create_html_with_tooltip(text, tooltip):
|
66 |
-
return f'''
|
67 |
-
<div class="tooltip-wrapper">
|
68 |
-
{text}
|
69 |
-
<span class="tooltip">{tooltip}</span>
|
70 |
-
</div>
|
71 |
-
'''
|
72 |
-
|
73 |
def update_leaderboard(sort_by):
|
74 |
sorted_df = df.sort_values(by=sort_by, ascending=False, ignore_index=True)
|
75 |
sorted_df['Rank'] = range(1, len(sorted_df) + 1)
|
76 |
|
77 |
-
#
|
78 |
-
sorted_df['Methods'] = sorted_df.apply(lambda row: create_html_with_tooltip(row['Methods'], row['Prompts']), axis=1)
|
79 |
-
|
80 |
-
# Drop the 'Prompts' column as we don't want to display it directly
|
81 |
-
sorted_df = sorted_df.drop(columns=['Prompts'])
|
82 |
-
|
83 |
html = sorted_df.to_html(index=False, escape=False)
|
84 |
|
|
|
85 |
for column in sorted_df.columns:
|
86 |
html = html.replace(f'<th>{column}</th>',
|
87 |
f'<th><a href="#" onclick="sortBy(\'{column}\'); return false;">{column}</a></th>')
|
|
|
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 {
|
|
|
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()
|
50 |
prompts = json.loads(json_data)# Sample data for the leaderboard
|
|
|
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],
|
|
|
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>')
|