Spaces:
Sleeping
Sleeping
Delete model_list.py
Browse files- model_list.py +0 -79
model_list.py
DELETED
@@ -1,79 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import numpy as np
|
4 |
-
import pandas as pd
|
5 |
-
import requests
|
6 |
-
from huggingface_hub.hf_api import SpaceInfo
|
7 |
-
|
8 |
-
SHEET_ID = '1L7AHpWMVU_kZVLcsk8H2FTizgzeVxWPDoBxw7K8KHXw'
|
9 |
-
SHEET_NAME = 'model'
|
10 |
-
csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'
|
11 |
-
|
12 |
-
class ModelList:
|
13 |
-
def __init__(self):
|
14 |
-
self.table = pd.read_csv(csv_url)
|
15 |
-
self.table = self.table.astype({'Year':'string'})
|
16 |
-
self._preprocess_table()
|
17 |
-
|
18 |
-
self.table_header = '''
|
19 |
-
<tr>
|
20 |
-
<td width="15%">Name</td>
|
21 |
-
<td width="10%">Year Published</td>
|
22 |
-
<td width="10%">Source</td>
|
23 |
-
<td width="30%">About</td>
|
24 |
-
<td width="10%">Task</td>
|
25 |
-
<td width="15%">Training Data Type</td>
|
26 |
-
<td width="10%">Publication</td>
|
27 |
-
</tr>'''
|
28 |
-
|
29 |
-
def _preprocess_table(self) -> None:
|
30 |
-
self.table['name_lowercase'] = self.table['Name'].str.lower()
|
31 |
-
|
32 |
-
rows = []
|
33 |
-
for row in self.table.itertuples():
|
34 |
-
source = f'<a href="{row.Source}" target="_blank">Link</a>' if isinstance(
|
35 |
-
row.Source, str) else ''
|
36 |
-
paper = f'<a href="{row.Paper}" target="_blank">Link</a>' if isinstance(
|
37 |
-
row.Source, str) else ''
|
38 |
-
row = f'''
|
39 |
-
<tr>
|
40 |
-
<td>{row.Name}</td>
|
41 |
-
<td>{row.Year}</td>
|
42 |
-
<td>{source}</td>
|
43 |
-
<td>{row.About}</td>
|
44 |
-
<td>{row.task}</td>
|
45 |
-
<td>{row.data}</td>
|
46 |
-
<td>{paper}</td>
|
47 |
-
</tr>'''
|
48 |
-
rows.append(row)
|
49 |
-
self.table['html_table_content'] = rows
|
50 |
-
|
51 |
-
def render(self, search_query: str,
|
52 |
-
case_sensitive: bool,
|
53 |
-
filter_names: list[str],
|
54 |
-
data_types: list[str]) -> tuple[int, str]:
|
55 |
-
df = self.table
|
56 |
-
if search_query:
|
57 |
-
if case_sensitive:
|
58 |
-
df = df[df.name.str.contains(search_query)]
|
59 |
-
else:
|
60 |
-
df = df[df.name_lowercase.str.contains(search_query.lower())]
|
61 |
-
df = self.filter_table(df, filter_names, data_types)
|
62 |
-
result = self.to_html(df, self.table_header)
|
63 |
-
return result
|
64 |
-
|
65 |
-
@staticmethod
|
66 |
-
def filter_table(df: pd.DataFrame, filter_names: list[str], data_types: list[str]) -> pd.DataFrame:
|
67 |
-
df = df.loc[df.task.isin(set(filter_names))]
|
68 |
-
df = df.loc[df.data.isin(set(data_types))]
|
69 |
-
return df
|
70 |
-
|
71 |
-
@staticmethod
|
72 |
-
def to_html(df: pd.DataFrame, table_header: str) -> str:
|
73 |
-
table_data = ''.join(df.html_table_content)
|
74 |
-
html = f'''
|
75 |
-
<table>
|
76 |
-
{table_header}
|
77 |
-
{table_data}
|
78 |
-
</table>'''
|
79 |
-
return html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|