Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,12 @@ import httpx
|
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
5 |
|
6 |
-
|
7 |
async def get_splits(dataset_name: str) -> Dict[str, List[Dict]]:
|
8 |
URL = f"https://datasets-server.huggingface.co/splits?dataset={dataset_name}"
|
9 |
async with httpx.AsyncClient() as session:
|
10 |
response = await session.get(URL)
|
11 |
return response.json()
|
12 |
|
13 |
-
|
14 |
async def get_valid_datasets() -> Dict[str, List[str]]:
|
15 |
URL = f"https://datasets-server.huggingface.co/valid"
|
16 |
async with httpx.AsyncClient() as session:
|
@@ -18,7 +16,6 @@ async def get_valid_datasets() -> Dict[str, List[str]]:
|
|
18 |
datasets = response.json()["valid"]
|
19 |
return gr.Dropdown.update(choices=datasets, value="glue")
|
20 |
|
21 |
-
|
22 |
async def get_first_rows(dataset: str, config: str, split: str) -> Dict[str, Dict[str, List[Dict]]]:
|
23 |
URL = f"https://datasets-server.huggingface.co/first-rows?dataset={dataset}&config={config}&split={split}"
|
24 |
async with httpx.AsyncClient() as session:
|
@@ -28,28 +25,31 @@ async def get_first_rows(dataset: str, config: str, split: str) -> Dict[str, Dic
|
|
28 |
def get_df_from_rows(api_output):
|
29 |
return pd.DataFrame([row["row"] for row in api_output["rows"]])
|
30 |
|
31 |
-
|
32 |
async def update_configs(dataset_name: str):
|
33 |
splits = await get_splits(dataset_name)
|
34 |
all_configs = sorted(set([s["config"] for s in splits["splits"]]))
|
35 |
return (gr.Dropdown.update(choices=all_configs, value=all_configs[0]),
|
36 |
splits)
|
37 |
|
38 |
-
|
39 |
async def update_splits(config_name: str, state: gr.State):
|
40 |
splits_for_config = sorted(set([s["split"] for s in state["splits"] if s["config"] == config_name]))
|
41 |
dataset_name = state["splits"][0]["dataset"]
|
42 |
dataset = await update_dataset(splits_for_config[0], config_name, dataset_name)
|
43 |
return (gr.Dropdown.update(choices=splits_for_config, value=splits_for_config[0]), dataset)
|
44 |
|
45 |
-
|
46 |
async def update_dataset(split_name: str, config_name: str, dataset_name: str):
|
47 |
rows = await get_first_rows(dataset_name, config_name, split_name)
|
48 |
df = get_df_from_rows(rows)
|
49 |
return df
|
50 |
|
|
|
|
|
|
|
51 |
|
52 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
53 |
splits_data = gr.State()
|
54 |
with gr.Row():
|
55 |
dataset_name = gr.Dropdown(label="Dataset")
|
@@ -64,7 +64,6 @@ with gr.Blocks() as demo:
|
|
64 |
|
65 |
demo.launch(debug=True)
|
66 |
|
67 |
-
|
68 |
# original: https://huggingface.co/spaces/freddyaboulton/dataset-viewer -- Freddy thanks! Your examples are the best.
|
69 |
# playlist on Gradio and Mermaid: https://www.youtube.com/watch?v=o7kCD4aWMR4&list=PLHgX2IExbFosW7hWNryq8hs2bt2aj91R-
|
70 |
# Link to Mermaid model and code: [![](https://mermaid.ink/img/pako:eNp1U8mO2zAM_RXCZ-eQpZccCmSZTIpOMQESIAdnDrRMx0JkydXSNDOYfy_lpUgD1AfBfnx8fCTlj0SYgpJ5UipzFRVaD4flSQM_YjwafcVJ9-FCfrbYVGA0ZQeLUkt9futiOM72pEh4QFijR9iTf2tzsx3Z0ti6hxslvb_Lm0TSNPvBDhQsg1TFXXAag7NBef_9hdDqFA6knbEbdgvGwu7mjRXVkDOLOV-yNXmytdQEsoROvTfi4EhK9XTSxUNz_mo4uVHm1lPyce-uR1k_n2RHymHRNPAvNXaTT7NVZYwjeDECVbS4UiYUAyc2lc-yFoPXxkujHaAl2G54PCjIpfBssZAGtsZ5KlLYkjWXkMLiuOfjPVhiymr3_x4qS7wicneTFuMW6Gdxlb6Cb7oJvt1LbEpMso08sza8MnqskA9jL27Ij72Jafb0G-tGkQNTdgKOy_XcFP5GDxFbWsJLV3FQid2LWfZsfpHVqAXBCBYa1e2dAHUBu5Ar6dgby0ghPWxQWk2Oh_L0M0h_S2Ep0YHUrXFHXD_msefo5XEkfFWBK8atdkA7mgfoalpATJI0qfnWoCz4b_iI0VPiK6rplMz5taASg_Kn5KQ_mYrBm_1Ni2TubaA0CU2BntYSeQl1Mi9ROfr8A8FBGds?type=png)](https://mermaid.live/edit#pako:eNp1U8mO2zAM_RXCZ-eQpZccCmSZTIpOMQESIAdnDrRMx0JkydXSNDOYfy_lpUgD1AfBfnx8fCTlj0SYgpJ5UipzFRVaD4flSQM_YjwafcVJ9-FCfrbYVGA0ZQeLUkt9futiOM72pEh4QFijR9iTf2tzsx3Z0ti6hxslvb_Lm0TSNPvBDhQsg1TFXXAag7NBef_9hdDqFA6knbEbdgvGwu7mjRXVkDOLOV-yNXmytdQEsoROvTfi4EhK9XTSxUNz_mo4uVHm1lPyce-uR1k_n2RHymHRNPAvNXaTT7NVZYwjeDECVbS4UiYUAyc2lc-yFoPXxkujHaAl2G54PCjIpfBssZAGtsZ5KlLYkjWXkMLiuOfjPVhiymr3_x4qS7wicneTFuMW6Gdxlb6Cb7oJvt1LbEpMso08sza8MnqskA9jL27Ij72Jafb0G-tGkQNTdgKOy_XcFP5GDxFbWsJLV3FQid2LWfZsfpHVqAXBCBYa1e2dAHUBu5Ar6dgby0ghPWxQWk2Oh_L0M0h_S2Ep0YHUrXFHXD_msefo5XEkfFWBK8atdkA7mgfoalpATJI0qfnWoCz4b_iI0VPiK6rplMz5taASg_Kn5KQ_mYrBm_1Ni2TubaA0CU2BntYSeQl1Mi9ROfr8A8FBGds)
|
|
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
5 |
|
|
|
6 |
async def get_splits(dataset_name: str) -> Dict[str, List[Dict]]:
|
7 |
URL = f"https://datasets-server.huggingface.co/splits?dataset={dataset_name}"
|
8 |
async with httpx.AsyncClient() as session:
|
9 |
response = await session.get(URL)
|
10 |
return response.json()
|
11 |
|
|
|
12 |
async def get_valid_datasets() -> Dict[str, List[str]]:
|
13 |
URL = f"https://datasets-server.huggingface.co/valid"
|
14 |
async with httpx.AsyncClient() as session:
|
|
|
16 |
datasets = response.json()["valid"]
|
17 |
return gr.Dropdown.update(choices=datasets, value="glue")
|
18 |
|
|
|
19 |
async def get_first_rows(dataset: str, config: str, split: str) -> Dict[str, Dict[str, List[Dict]]]:
|
20 |
URL = f"https://datasets-server.huggingface.co/first-rows?dataset={dataset}&config={config}&split={split}"
|
21 |
async with httpx.AsyncClient() as session:
|
|
|
25 |
def get_df_from_rows(api_output):
|
26 |
return pd.DataFrame([row["row"] for row in api_output["rows"]])
|
27 |
|
|
|
28 |
async def update_configs(dataset_name: str):
|
29 |
splits = await get_splits(dataset_name)
|
30 |
all_configs = sorted(set([s["config"] for s in splits["splits"]]))
|
31 |
return (gr.Dropdown.update(choices=all_configs, value=all_configs[0]),
|
32 |
splits)
|
33 |
|
|
|
34 |
async def update_splits(config_name: str, state: gr.State):
|
35 |
splits_for_config = sorted(set([s["split"] for s in state["splits"] if s["config"] == config_name]))
|
36 |
dataset_name = state["splits"][0]["dataset"]
|
37 |
dataset = await update_dataset(splits_for_config[0], config_name, dataset_name)
|
38 |
return (gr.Dropdown.update(choices=splits_for_config, value=splits_for_config[0]), dataset)
|
39 |
|
|
|
40 |
async def update_dataset(split_name: str, config_name: str, dataset_name: str):
|
41 |
rows = await get_first_rows(dataset_name, config_name, split_name)
|
42 |
df = get_df_from_rows(rows)
|
43 |
return df
|
44 |
|
45 |
+
# Guido von Roissum: https://www.youtube.com/watch?v=-DVyjdw4t9I
|
46 |
+
# Guido says indentation style in python helps readability. Emoji's do too: https://www.kaggle.com/datasets/subinium/emojiimage-dataset
|
47 |
+
# four spaces was a compromise. Google style guide (2 spaces) Harder at a glance to understand code. 8 spaces is a whole tab stop. after inddent levels you have little room left.
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
+
gr.Markdown("<h1><center>🥫Datasets🎨</center></h1>")
|
51 |
+
gr.Markdown("""<div align="center">Curated Datasets: <a href = "https://www.kaggle.com/datasets">Kaggle</a>. <a href="https://www.nlm.nih.gov/research/umls/index.html">NLM UMLS</a>. <a href="https://loinc.org/downloads/">LOINC</a>. <a href="https://www.cms.gov/medicare/icd-10/2022-icd-10-cm">ICD10 Diagnosis</a>. <a href="https://icd.who.int/dev11/downloads">ICD11</a>. <a href="https://paperswithcode.com/datasets?q=medical&v=lst&o=newest">Papers,Code,Datasets for SOTA in Medicine</a>. <a href="https://www.cms.gov/medicare-coverage-database/downloads/downloads.aspx">CMS Downloads</a>. <a href="https://www.cms.gov/medicare/fraud-and-abuse/physicianselfreferral/list_of_codes">CMS CPT and HCPCS Procedures and Services</a> """)
|
52 |
+
|
53 |
splits_data = gr.State()
|
54 |
with gr.Row():
|
55 |
dataset_name = gr.Dropdown(label="Dataset")
|
|
|
64 |
|
65 |
demo.launch(debug=True)
|
66 |
|
|
|
67 |
# original: https://huggingface.co/spaces/freddyaboulton/dataset-viewer -- Freddy thanks! Your examples are the best.
|
68 |
# playlist on Gradio and Mermaid: https://www.youtube.com/watch?v=o7kCD4aWMR4&list=PLHgX2IExbFosW7hWNryq8hs2bt2aj91R-
|
69 |
# Link to Mermaid model and code: [![](https://mermaid.ink/img/pako:eNp1U8mO2zAM_RXCZ-eQpZccCmSZTIpOMQESIAdnDrRMx0JkydXSNDOYfy_lpUgD1AfBfnx8fCTlj0SYgpJ5UipzFRVaD4flSQM_YjwafcVJ9-FCfrbYVGA0ZQeLUkt9futiOM72pEh4QFijR9iTf2tzsx3Z0ti6hxslvb_Lm0TSNPvBDhQsg1TFXXAag7NBef_9hdDqFA6knbEbdgvGwu7mjRXVkDOLOV-yNXmytdQEsoROvTfi4EhK9XTSxUNz_mo4uVHm1lPyce-uR1k_n2RHymHRNPAvNXaTT7NVZYwjeDECVbS4UiYUAyc2lc-yFoPXxkujHaAl2G54PCjIpfBssZAGtsZ5KlLYkjWXkMLiuOfjPVhiymr3_x4qS7wicneTFuMW6Gdxlb6Cb7oJvt1LbEpMso08sza8MnqskA9jL27Ij72Jafb0G-tGkQNTdgKOy_XcFP5GDxFbWsJLV3FQid2LWfZsfpHVqAXBCBYa1e2dAHUBu5Ar6dgby0ghPWxQWk2Oh_L0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