IAMJB commited on
Commit
bc87bb9
·
1 Parent(s): e4eebea

Leaderboard

Browse files
Files changed (5) hide show
  1. README.md +1 -1
  2. app.py +94 -87
  3. author_leaderboard_tab.py +32 -0
  4. df/PaperCentral.py +1 -1
  5. df/author_leaderboard.py +152 -0
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: ⚡
5
  colorFrom: red
6
  colorTo: purple
7
  sdk: gradio
8
- sdk_version: 4.44.0
9
  app_file: app.py
10
  pinned: false
11
  header: mini
 
5
  colorFrom: red
6
  colorTo: purple
7
  sdk: gradio
8
+ sdk_version: 5.0.2
9
  app_file: app.py
10
  pinned: false
11
  header: mini
app.py CHANGED
@@ -3,6 +3,7 @@ from df.PaperCentral import PaperCentral
3
  from gradio_calendar import Calendar
4
  from datetime import datetime, timedelta
5
  from typing import Union, List
 
6
 
7
  # Initialize the PaperCentral class instance
8
  paper_central_df = PaperCentral()
@@ -11,97 +12,103 @@ paper_central_df = PaperCentral()
11
  with gr.Blocks(css="style.css") as demo:
12
  gr.Markdown("# Paper Central")
13
 
14
- with gr.Accordion(label="⭐Release notes", open=False):
15
- gr.Markdown("""
16
- 4/10/2024 - You can now filter by Title
17
- """)
18
-
19
- # Create a row for navigation buttons and calendar
20
- with gr.Row():
21
- with gr.Column(scale=1):
22
- # Define the 'Next Day' and 'Previous Day' buttons
23
- next_day_btn = gr.Button("Next Day")
24
- prev_day_btn = gr.Button("Previous Day")
25
- with gr.Column(scale=4):
26
- # Define the calendar component for date selection
27
- calendar = Calendar(
28
- type="datetime",
29
- label="Select a date",
30
- info="Click the calendar icon to bring up the calendar.",
31
- value=datetime.today().strftime('%Y-%m-%d') # Default to today's date
32
- )
33
-
34
- # Create a row for Hugging Face options and Conference options
35
- with gr.Row():
36
- with gr.Column():
37
- # Define the checkbox group for Hugging Face options
38
- cat_options = gr.CheckboxGroup(
39
- label="Category",
40
- choices=[
41
- 'cs.*',
42
- 'eess.*',
43
- 'econ.*',
44
- 'math.*',
45
- 'astro-ph.*',
46
- 'cond-mat.*',
47
- 'gr-qc',
48
- 'hep-ex',
49
- 'hep-lat',
50
- 'hep-ph',
51
- 'hep-th',
52
- 'math-ph',
53
- 'nlin.*',
54
- 'nucl-ex',
55
- 'nucl-th',
56
- 'physics.*',
57
- 'quant-ph',
58
- 'q-bio.*',
59
- 'q-fin.*',
60
- 'stat.*',
61
- ],
62
- value=["cs.*"]
63
- )
64
- hf_options = gr.CheckboxGroup(
65
- label="Hugging Face options",
66
- choices=["🤗 paper-page", "datasets", "models", "spaces", "github"],
67
- value=[],
68
- elem_id="hf_options"
69
- )
70
 
71
- with gr.Column():
72
- # Define the checkbox group for Conference options
73
- conference_options = gr.CheckboxGroup(
74
- label="Conference options",
75
- choices=["In proceedings"] + PaperCentral.CONFERENCES
76
- )
77
- with gr.Row():
78
- # Define a Textbox for author search
79
- author_search = gr.Textbox(
80
- label="Search Authors",
81
- placeholder="Enter author name",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  )
83
- title_search = gr.Textbox(
84
- label="Search Title",
85
- placeholder="Enter keywords",
 
 
86
  )
87
 
88
- # Define the Dataframe component to display paper data
89
- # List of columns in your DataFrame
90
- columns = paper_central_df.COLUMNS_START_PAPER_PAGE
91
-
92
- paper_central_component = gr.Dataframe(
93
- label="Paper Data",
94
- value=paper_central_df.df_prettified[columns],
95
- datatype=[
96
- paper_central_df.DATATYPES[column]
97
- for column in columns
98
- ],
99
- row_count=(0, "dynamic"),
100
- interactive=False,
101
- height=1000,
102
- elem_id="table",
103
- wrap=True,
104
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
 
107
  # Define function to move to the next day
 
3
  from gradio_calendar import Calendar
4
  from datetime import datetime, timedelta
5
  from typing import Union, List
6
+ from author_leaderboard_tab import author_leaderboard_tab
7
 
8
  # Initialize the PaperCentral class instance
9
  paper_central_df = PaperCentral()
 
12
  with gr.Blocks(css="style.css") as demo:
13
  gr.Markdown("# Paper Central")
14
 
15
+ with gr.Tab("Paper-central"):
16
+ with gr.Accordion(label="⭐Release notes", open=False):
17
+ gr.Markdown("""
18
+ - 8/10/2024 - MICCAI proceedings added
19
+ - 7/10/2024 - COLM2024 proceedings added
20
+ - 4/10/2024 - You can now filter by Title
21
+ """)
22
+
23
+ # Create a row for navigation buttons and calendar
24
+ with gr.Row():
25
+ with gr.Column(scale=1):
26
+ # Define the 'Next Day' and 'Previous Day' buttons
27
+ next_day_btn = gr.Button("Next Day")
28
+ prev_day_btn = gr.Button("Previous Day")
29
+ with gr.Column(scale=4):
30
+ # Define the calendar component for date selection
31
+ calendar = Calendar(
32
+ type="datetime",
33
+ label="Select a date",
34
+ info="Click the calendar icon to bring up the calendar.",
35
+ value=datetime.today().strftime('%Y-%m-%d') # Default to today's date
36
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
+ # Create a row for Hugging Face options and Conference options
39
+ with gr.Row():
40
+ with gr.Column():
41
+ # Define the checkbox group for Hugging Face options
42
+ cat_options = gr.CheckboxGroup(
43
+ label="Category",
44
+ choices=[
45
+ 'cs.*',
46
+ 'eess.*',
47
+ 'econ.*',
48
+ 'math.*',
49
+ 'astro-ph.*',
50
+ 'cond-mat.*',
51
+ 'gr-qc',
52
+ 'hep-ex',
53
+ 'hep-lat',
54
+ 'hep-ph',
55
+ 'hep-th',
56
+ 'math-ph',
57
+ 'nlin.*',
58
+ 'nucl-ex',
59
+ 'nucl-th',
60
+ 'physics.*',
61
+ 'quant-ph',
62
+ 'q-bio.*',
63
+ 'q-fin.*',
64
+ 'stat.*',
65
+ ],
66
+ value=["cs.*"]
67
  )
68
+ hf_options = gr.CheckboxGroup(
69
+ label="Hugging Face options",
70
+ choices=["🤗 artifacts", "datasets", "models", "spaces", "github"],
71
+ value=[],
72
+ elem_id="hf_options"
73
  )
74
 
75
+ with gr.Column():
76
+ # Define the checkbox group for Conference options
77
+ conference_options = gr.CheckboxGroup(
78
+ label="Conference options",
79
+ choices=["In proceedings"] + PaperCentral.CONFERENCES
80
+ )
81
+ with gr.Row():
82
+ # Define a Textbox for author search
83
+ author_search = gr.Textbox(
84
+ label="Search Authors",
85
+ placeholder="Enter author name",
86
+ )
87
+ title_search = gr.Textbox(
88
+ label="Search Title",
89
+ placeholder="Enter keywords",
90
+ )
91
+
92
+ # Define the Dataframe component to display paper data
93
+ # List of columns in your DataFrame
94
+ columns = paper_central_df.COLUMNS_START_PAPER_PAGE
95
+
96
+ paper_central_component = gr.Dataframe(
97
+ label="Paper Data",
98
+ value=paper_central_df.df_prettified[columns],
99
+ datatype=[
100
+ paper_central_df.DATATYPES[column]
101
+ for column in columns
102
+ ],
103
+ row_count=(0, "dynamic"),
104
+ interactive=False,
105
+ max_height=1000,
106
+ elem_id="table",
107
+ wrap=True,
108
+ )
109
+
110
+ with gr.Tab("Leaderboard"):
111
+ author_leaderboard_tab()
112
 
113
 
114
  # Define function to move to the next day
author_leaderboard_tab.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from df.author_leaderboard import AuthorLeaderboard
3
+
4
+ def author_leaderboard_tab():
5
+ # Initialize the AuthorLeaderboard class
6
+ leaderboard = AuthorLeaderboard()
7
+
8
+ with gr.Row():
9
+ gr.Markdown("## Author Leaderboard")
10
+ with gr.Row():
11
+ author_search_input = gr.Textbox(
12
+ label="Search by Author Name",
13
+ placeholder="Enter author name...",
14
+ lines=1,
15
+ )
16
+ with gr.Row():
17
+ leaderboard_component = gr.Dataframe(
18
+ label="Leaderboard",
19
+ value=leaderboard.df_prettified,
20
+ datatype=[leaderboard.DATATYPES[column] for column in leaderboard.COLUMNS_ORDER],
21
+ row_count=(0, "dynamic"),
22
+ interactive=False,
23
+ max_height=1000,
24
+ wrap=True,
25
+ )
26
+
27
+ # Define the interaction
28
+ author_search_input.change(
29
+ leaderboard.filter,
30
+ inputs=[author_search_input],
31
+ outputs=[leaderboard_component]
32
+ )
df/PaperCentral.py CHANGED
@@ -356,7 +356,7 @@ class PaperCentral:
356
 
357
  # HF options
358
  if hf_options:
359
- if "🤗 paper-page" in hf_options:
360
  # Filter rows where 'paper_page' is not empty or NaN
361
  filtered_df = filtered_df[
362
  (filtered_df['paper_page'] != "") & (filtered_df['paper_page'].notna())
 
356
 
357
  # HF options
358
  if hf_options:
359
+ if "🤗 artifacts" in hf_options:
360
  # Filter rows where 'paper_page' is not empty or NaN
361
  filtered_df = filtered_df[
362
  (filtered_df['paper_page'] != "") & (filtered_df['paper_page'].notna())
df/author_leaderboard.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from typing import List, Dict, Optional
3
+ import gradio as gr
4
+ from datasets import load_dataset
5
+ import numpy as np
6
+
7
+ class AuthorLeaderboard:
8
+ """
9
+ A class to manage and process author leaderboard data for display in a Gradio Dataframe component.
10
+ """
11
+
12
+ # Class-level constants defining columns and their data types
13
+ COLUMNS_ORDER: List[str] = [
14
+ 'Rank',
15
+ 'Author',
16
+ 'Total Artifacts',
17
+ 'Avg Artifacts per Paper',
18
+ 'Total Papers',
19
+ 'Total Models',
20
+ 'Total Datasets',
21
+ 'Total Spaces',
22
+ 'Upvotes',
23
+ 'Comments',
24
+ ]
25
+
26
+ DATATYPES: Dict[str, str] = {
27
+ 'Rank': 'str',
28
+ 'Author': 'markdown',
29
+ 'Total Artifacts': 'int',
30
+ 'Avg Artifacts per Paper': 'float',
31
+ 'Total Papers': 'int',
32
+ 'Total Models': 'int',
33
+ 'Total Datasets': 'int',
34
+ 'Total Spaces': 'int',
35
+ 'Upvotes': 'int',
36
+ 'Comments': 'int',
37
+ }
38
+
39
+ EMOTICONS = {
40
+ 1: '🥇',
41
+ 2: '🥈',
42
+ 3: '🥉'
43
+ }
44
+
45
+ def __init__(self):
46
+ """
47
+ Initialize the AuthorLeaderboard class by loading and processing the dataset.
48
+ """
49
+ self.df_raw: pd.DataFrame = self.get_df()
50
+ self.df_prettified: pd.DataFrame = self.prettify(self.df_raw)
51
+
52
+ @staticmethod
53
+ def get_df() -> pd.DataFrame:
54
+ """
55
+ Load and process the leaderboard dataset.
56
+
57
+ Returns:
58
+ pd.DataFrame: The processed DataFrame.
59
+ """
60
+ # Load the dataset from the Hugging Face Hub
61
+ dataset = load_dataset('IAMJB/paper-central-leaderboard', split='leaderboard')
62
+ df = dataset.to_pandas()
63
+
64
+ # Calculate total artifacts
65
+ df['Total Artifacts'] = df['num_models'] + df['num_datasets'] + df['num_spaces']
66
+
67
+ # Calculate average artifacts per paper
68
+ df['Avg Artifacts per Paper'] = df['Total Artifacts'] / df['num_papers']
69
+ df['Avg Artifacts per Paper'] = df['Avg Artifacts per Paper'].round(2)
70
+
71
+ # Rename columns for clarity
72
+ df.rename(columns={
73
+ 'name': 'Author',
74
+ 'num_papers': 'Total Papers',
75
+ 'num_models': 'Total Models',
76
+ 'num_datasets': 'Total Datasets',
77
+ 'num_spaces': 'Total Spaces',
78
+ 'upvotes': 'Upvotes',
79
+ 'num_comments': 'Comments',
80
+ }, inplace=True)
81
+
82
+ return df
83
+
84
+ def prettify(self, df: pd.DataFrame) -> pd.DataFrame:
85
+ """
86
+ Prettify the DataFrame by adding rankings, emoticons, and markdown links.
87
+
88
+ Args:
89
+ df (pd.DataFrame): The DataFrame to prettify.
90
+
91
+ Returns:
92
+ pd.DataFrame: The prettified DataFrame.
93
+ """
94
+ df = df.copy()
95
+
96
+ # Sort authors by Total Artifacts descending
97
+ df.sort_values(by='Total Artifacts', ascending=False, inplace=True)
98
+
99
+ # Reset index to get ranks
100
+ df.reset_index(drop=True, inplace=True)
101
+ df.index += 1 # Start ranks from 1
102
+
103
+ # Add Rank column
104
+ df['Rank'] = df.index
105
+
106
+ # Add emoticons for top 3 ranks
107
+ df['Rank'] = df['Rank'].apply(lambda x: f"{self.EMOTICONS.get(x, '')} {x}" if x <= 3 else f"{x}")
108
+
109
+ # Convert 'Author' to markdown with profile links if 'username' is available
110
+ df['Author'] = df.apply(self._create_author_link, axis=1)
111
+
112
+ # Select columns to display
113
+ df = df[self.COLUMNS_ORDER]
114
+
115
+ return df
116
+
117
+ def _create_author_link(self, row: pd.Series) -> str:
118
+ """
119
+ Create a markdown link for the author's profile.
120
+
121
+ Args:
122
+ row (pd.Series): A row from the DataFrame.
123
+
124
+ Returns:
125
+ str: The markdown link for the author.
126
+ """
127
+ if pd.notna(row.get('username')) and row['username']:
128
+ profile_url = f"https://huggingface.co/{row['username']}"
129
+ return f"[{row['Author']}]({profile_url})"
130
+ else:
131
+ return row['Author']
132
+
133
+ def filter(self, author_search_input: Optional[str] = None) -> gr.update:
134
+ """
135
+ Filter the DataFrame based on the author search input.
136
+
137
+ Args:
138
+ author_search_input (Optional[str]): The author name to search for.
139
+
140
+ Returns:
141
+ gr.Update: An update object for the Gradio Dataframe component.
142
+ """
143
+ filtered_df: pd.DataFrame = self.df_prettified.copy()
144
+
145
+ if author_search_input:
146
+ search_string = author_search_input.lower()
147
+ filtered_df = filtered_df[filtered_df['Author'].str.lower().str.contains(search_string)]
148
+
149
+ # Get the corresponding data types for the columns
150
+ datatypes: List[str] = [self.DATATYPES.get(col, 'str') for col in filtered_df.columns]
151
+
152
+ return gr.update(value=filtered_df, datatype=datatypes)