from __future__ import annotations import numpy as np import pandas as pd class PaperList: def __init__(self): self.organization_name = "ICML2023" self.table = pd.read_csv("papers.csv") self._preprocess_table() self.table_header = """ Title Authors arXiv GitHub Paper pages Spaces Models Datasets Claimed """ def _preprocess_table(self) -> None: self.table["title_lowercase"] = self.table.title.str.lower() rows = [] for row in self.table.itertuples(): title = f"{row.title}" arxiv = f'arXiv' if isinstance(row.arxiv, str) else "" github = f'GitHub' if isinstance(row.github, str) else "" hf_paper = ( f'Paper page' if isinstance(row.hf_paper, str) else "" ) hf_space = f'Space' if isinstance(row.hf_space, str) else "" hf_model = f'Model' if isinstance(row.hf_model, str) else "" hf_dataset = ( f'Dataset' if isinstance(row.hf_dataset, str) else "" ) author_linked = "✅" if ~np.isnan(row.n_linked_authors) and row.n_linked_authors > 0 else "" n_linked_authors = "" if np.isnan(row.n_linked_authors) else int(row.n_linked_authors) n_authors = "" if np.isnan(row.n_authors) else int(row.n_authors) claimed_paper = "" if n_linked_authors == "" else f"{n_linked_authors}/{n_authors} {author_linked}" row = f""" {title} {row.authors} {arxiv} {github} {hf_paper} {hf_space} {hf_model} {hf_dataset} {claimed_paper} """ rows.append(row) self.table["html_table_content"] = rows def render(self, search_query: str, case_sensitive: bool, filter_names: list[str]) -> tuple[str, str]: df = self.table if search_query: if case_sensitive: df = df[df.title.str.contains(search_query)] else: df = df[df.title_lowercase.str.contains(search_query.lower())] has_arxiv = "arXiv" in filter_names has_github = "GitHub" in filter_names has_hf_space = "Space" in filter_names has_hf_model = "Model" in filter_names has_hf_dataset = "Dataset" in filter_names df = self.filter_table(df, has_arxiv, has_github, has_hf_space, has_hf_model, has_hf_dataset) n_claimed = len(df[df.n_linked_authors > 0]) return f"{len(df)} ({n_claimed} claimed)", self.to_html(df, self.table_header) @staticmethod def filter_table( df: pd.DataFrame, has_arxiv: bool, has_github: bool, has_hf_space: bool, has_hf_model: bool, has_hf_dataset: bool, ) -> pd.DataFrame: if has_arxiv: df = df[~df.arxiv.isna()] if has_github: df = df[~df.github.isna()] if has_hf_space: df = df[~df.hf_space.isna()] if has_hf_model: df = df[~df.hf_model.isna()] if has_hf_dataset: df = df[~df.hf_dataset.isna()] return df @staticmethod def to_html(df: pd.DataFrame, table_header: str) -> str: table_data = "".join(df.html_table_content) html = f""" {table_header} {table_data}
""" return html