Spaces:
Runtime error
Runtime error
Refactor. Pre-generate HTML rows
Browse files
papers.py
CHANGED
|
@@ -6,7 +6,7 @@ import pandas as pd
|
|
| 6 |
class PaperList:
|
| 7 |
def __init__(self):
|
| 8 |
self.table = pd.read_csv('papers.csv')
|
| 9 |
-
self.
|
| 10 |
|
| 11 |
self.table_header = '''
|
| 12 |
<tr>
|
|
@@ -19,6 +19,34 @@ class PaperList:
|
|
| 19 |
<td width="5%">Hugging Face Spaces</td>
|
| 20 |
</tr>'''
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def render(self, search_query: str, case_sensitive: bool,
|
| 23 |
names_with_link: list[str]) -> tuple[int, str]:
|
| 24 |
df = self.table
|
|
@@ -48,36 +76,10 @@ class PaperList:
|
|
| 48 |
return df
|
| 49 |
|
| 50 |
def to_html(self, df: pd.DataFrame) -> str:
|
| 51 |
-
table_rows =
|
| 52 |
table_data = ''.join(table_rows)
|
| 53 |
html = f'''<table>
|
| 54 |
{self.table_header}
|
| 55 |
{table_data}
|
| 56 |
</table>'''
|
| 57 |
return html
|
| 58 |
-
|
| 59 |
-
def generate_table_rows(self, df: pd.DataFrame) -> list[str]:
|
| 60 |
-
rows = []
|
| 61 |
-
for row in df.itertuples():
|
| 62 |
-
paper = f'<a href="{row.url}">{row.title}</a>'
|
| 63 |
-
pdf = f'<a href="{row.pdf}">pdf</a>'
|
| 64 |
-
supp = f'<a href="{row.supp}">supp</a>' if isinstance(
|
| 65 |
-
row.supp, str) else ''
|
| 66 |
-
arxiv = f'<a href="{row.arxiv}">arXiv</a>' if isinstance(
|
| 67 |
-
row.arxiv, str) else ''
|
| 68 |
-
github = f'<a href="{row.github}">GitHub</a>' if isinstance(
|
| 69 |
-
row.github, str) else ''
|
| 70 |
-
hf_space = f'<a href="{row.hf_space}">Space</a>' if isinstance(
|
| 71 |
-
row.hf_space, str) else ''
|
| 72 |
-
row = f'''
|
| 73 |
-
<tr>
|
| 74 |
-
<td>{paper}</td>
|
| 75 |
-
<td>{row.authors}</td>
|
| 76 |
-
<td>{pdf}</td>
|
| 77 |
-
<td>{supp}</td>
|
| 78 |
-
<td>{arxiv}</td>
|
| 79 |
-
<td>{github}</td>
|
| 80 |
-
<td>{hf_space}</td>
|
| 81 |
-
</tr>'''
|
| 82 |
-
rows.append(row)
|
| 83 |
-
return rows
|
|
|
|
| 6 |
class PaperList:
|
| 7 |
def __init__(self):
|
| 8 |
self.table = pd.read_csv('papers.csv')
|
| 9 |
+
self._preprcess_table()
|
| 10 |
|
| 11 |
self.table_header = '''
|
| 12 |
<tr>
|
|
|
|
| 19 |
<td width="5%">Hugging Face Spaces</td>
|
| 20 |
</tr>'''
|
| 21 |
|
| 22 |
+
def _preprcess_table(self) -> None:
|
| 23 |
+
self.table['title_lowercase'] = self.table.title.str.lower()
|
| 24 |
+
|
| 25 |
+
rows = []
|
| 26 |
+
for row in self.table.itertuples():
|
| 27 |
+
paper = f'<a href="{row.url}">{row.title}</a>'
|
| 28 |
+
pdf = f'<a href="{row.pdf}">pdf</a>'
|
| 29 |
+
supp = f'<a href="{row.supp}">supp</a>' if isinstance(
|
| 30 |
+
row.supp, str) else ''
|
| 31 |
+
arxiv = f'<a href="{row.arxiv}">arXiv</a>' if isinstance(
|
| 32 |
+
row.arxiv, str) else ''
|
| 33 |
+
github = f'<a href="{row.github}">GitHub</a>' if isinstance(
|
| 34 |
+
row.github, str) else ''
|
| 35 |
+
hf_space = f'<a href="{row.hf_space}">Space</a>' if isinstance(
|
| 36 |
+
row.hf_space, str) else ''
|
| 37 |
+
row = f'''
|
| 38 |
+
<tr>
|
| 39 |
+
<td>{paper}</td>
|
| 40 |
+
<td>{row.authors}</td>
|
| 41 |
+
<td>{pdf}</td>
|
| 42 |
+
<td>{supp}</td>
|
| 43 |
+
<td>{arxiv}</td>
|
| 44 |
+
<td>{github}</td>
|
| 45 |
+
<td>{hf_space}</td>
|
| 46 |
+
</tr>'''
|
| 47 |
+
rows.append(row)
|
| 48 |
+
self.table['html_table_content'] = rows
|
| 49 |
+
|
| 50 |
def render(self, search_query: str, case_sensitive: bool,
|
| 51 |
names_with_link: list[str]) -> tuple[int, str]:
|
| 52 |
df = self.table
|
|
|
|
| 76 |
return df
|
| 77 |
|
| 78 |
def to_html(self, df: pd.DataFrame) -> str:
|
| 79 |
+
table_rows = df.html_table_content
|
| 80 |
table_data = ''.join(table_rows)
|
| 81 |
html = f'''<table>
|
| 82 |
{self.table_header}
|
| 83 |
{table_data}
|
| 84 |
</table>'''
|
| 85 |
return html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|