Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
class DataList:
|
5 |
-
def __init__(self):
|
6 |
-
SHEET_ID = '1BWKw2ygYQUUPcNdSJhW9OkXILWO5i-dCa5Uahn9dHNo'
|
7 |
-
SHEET_NAME = 'Datasets'
|
8 |
-
csv_url = f'https://docs.google.com/spreadsheets/d/{SHEET_ID}/gviz/tq?tqx=out:csv&sheet={SHEET_NAME}'
|
9 |
-
self.table = pd.read_csv(csv_url)
|
10 |
-
self.table = self.table.astype({'Year':'string'})
|
11 |
-
self._preprocess_table()
|
12 |
-
|
13 |
-
self.table_header = '''
|
14 |
-
<tr>
|
15 |
-
<td width="15%">Name</td>
|
16 |
-
<td width="10%">URL</td>
|
17 |
-
<td width="30%">About</td>
|
18 |
-
<td width="15%">Publisher</td>
|
19 |
-
<td width="10%">Year Updated</td>
|
20 |
-
<td width="10%">Type</td>
|
21 |
-
<td width="10%">Tag</td>
|
22 |
-
</tr>'''
|
23 |
-
|
24 |
-
def _preprocess_table(self) -> None:
|
25 |
-
self.table['name_lowercase'] = self.table['Name'].str.lower()
|
26 |
-
|
27 |
-
rows = []
|
28 |
-
for row in self.table.itertuples():
|
29 |
-
source = f'<a href="{row.URL}" target="_blank">Link</a>' if isinstance(
|
30 |
-
row.URL, str) else ''
|
31 |
-
row = f'''
|
32 |
-
<tr>
|
33 |
-
<td>{row.Name}</td>
|
34 |
-
<td>{source}</td>
|
35 |
-
<td>{row.About}</td>
|
36 |
-
<td>{row.Publisher}</td>
|
37 |
-
<td>{row.Year}</td>
|
38 |
-
<td>{row.Type}</td>
|
39 |
-
<td>{row.Tags}</td>
|
40 |
-
</tr>'''
|
41 |
-
rows.append(row)
|
42 |
-
self.table['html_table_content'] = rows
|
43 |
-
|
44 |
-
def render(self, search_query: str,
|
45 |
-
case_sensitive: bool,
|
46 |
-
filter_names: list[str],
|
47 |
-
data_types: list[str]) -> tuple[int, str]:
|
48 |
-
df = self.table
|
49 |
-
if search_query:
|
50 |
-
if case_sensitive:
|
51 |
-
df = df[df.name.str.contains(search_query)]
|
52 |
-
else:
|
53 |
-
df = df[df.name_lowercase.str.contains(search_query.lower())]
|
54 |
-
df = self.filter_table(df, filter_names, data_types)
|
55 |
-
result = self.to_html(df, self.table_header)
|
56 |
-
return result
|
57 |
-
|
58 |
-
@staticmethod
|
59 |
-
def filter_table(df: pd.DataFrame, filter_names: list[str], data_types: list[str]) -> pd.DataFrame:
|
60 |
-
df = df.loc[df.Type.isin(set(filter_names))]
|
61 |
-
df = df.loc[df.Tags.isin(set(data_types))]
|
62 |
-
return df
|
63 |
-
|
64 |
-
@staticmethod
|
65 |
-
def to_html(df: pd.DataFrame, table_header: str) -> str:
|
66 |
-
table_data = ''.join(df.html_table_content)
|
67 |
-
html = f'''
|
68 |
-
<table>
|
69 |
-
{table_header}
|
70 |
-
{table_data}
|
71 |
-
</table>'''
|
72 |
-
return html
|
73 |
def main():
|
74 |
data_list = DataList()
|
75 |
with gr.Blocks() as demo:
|
76 |
with gr.Row():
|
|
|
77 |
gr.Markdown("# Datasets for Healthcare Teams")
|
78 |
search_box = gr.Textbox( label='Search Name', placeholder='You can search for titles with regular expressions. e.g. (?<!sur)face',max_lines=1)
|
79 |
case_sensitive = gr.Checkbox(label='Case Sensitive')
|
|
|
1 |
import gradio as gr
|
2 |
+
from data_list import DataList
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def main():
|
5 |
data_list = DataList()
|
6 |
with gr.Blocks() as demo:
|
7 |
with gr.Row():
|
8 |
+
gr.Image(value="RAII.svg",scale=1,show_download_button=False,show_share_button=False,show_label=False,height=100,container=False)
|
9 |
gr.Markdown("# Datasets for Healthcare Teams")
|
10 |
search_box = gr.Textbox( label='Search Name', placeholder='You can search for titles with regular expressions. e.g. (?<!sur)face',max_lines=1)
|
11 |
case_sensitive = gr.Checkbox(label='Case Sensitive')
|