Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Dict
|
2 |
+
import httpx
|
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:
|
15 |
+
response = await session.get(URL)
|
16 |
+
datasets = response.json()["valid"]
|
17 |
+
return gr.Dropdown.update(choices=datasets, value="awacke1/ChatbotMemory.csv")
|
18 |
+
# The one to watch: https://huggingface.co/rungalileo
|
19 |
+
# rungalileo/medical_transcription_40
|
20 |
+
|
21 |
+
async def get_first_rows(dataset: str, config: str, split: str) -> Dict[str, Dict[str, List[Dict]]]:
|
22 |
+
URL = f"https://datasets-server.huggingface.co/first-rows?dataset={dataset}&config={config}&split={split}"
|
23 |
+
async with httpx.AsyncClient() as session:
|
24 |
+
response = await session.get(URL)
|
25 |
+
print(URL)
|
26 |
+
gr.Markdown(URL)
|
27 |
+
return response.json()
|
28 |
+
|
29 |
+
def get_df_from_rows(api_output):
|
30 |
+
dfFromSort = pd.DataFrame([row["row"] for row in api_output["rows"]])
|
31 |
+
try:
|
32 |
+
dfFromSort.sort_values(by=1, axis=1, ascending=True, inplace=False, kind='mergesort', na_position='last', ignore_index=False, key=None)
|
33 |
+
except:
|
34 |
+
print("Exception sorting due to keyerror?")
|
35 |
+
return dfFromSort
|
36 |
+
|
37 |
+
async def update_configs(dataset_name: str):
|
38 |
+
splits = await get_splits(dataset_name)
|
39 |
+
all_configs = sorted(set([s["config"] for s in splits["splits"]]))
|
40 |
+
return (gr.Dropdown.update(choices=all_configs, value=all_configs[0]),
|
41 |
+
splits)
|
42 |
+
|
43 |
+
async def update_splits(config_name: str, state: gr.State):
|
44 |
+
splits_for_config = sorted(set([s["split"] for s in state["splits"] if s["config"] == config_name]))
|
45 |
+
dataset_name = state["splits"][0]["dataset"]
|
46 |
+
dataset = await update_dataset(splits_for_config[0], config_name, dataset_name)
|
47 |
+
return (gr.Dropdown.update(choices=splits_for_config, value=splits_for_config[0]), dataset)
|
48 |
+
|
49 |
+
async def update_dataset(split_name: str, config_name: str, dataset_name: str):
|
50 |
+
rows = await get_first_rows(dataset_name, config_name, split_name)
|
51 |
+
df = get_df_from_rows(rows)
|
52 |
+
return df
|
53 |
+
|
54 |
+
# Guido von Roissum: https://www.youtube.com/watch?v=-DVyjdw4t9I
|
55 |
+
async def update_URL(dataset: str, config: str, split: str) -> str:
|
56 |
+
URL = f"https://datasets-server.huggingface.co/first-rows?dataset={dataset}&config={config}&split={split}"
|
57 |
+
URL = f"https://huggingface.co/datasets/{split}"
|
58 |
+
return (URL)
|
59 |
+
|
60 |
+
async def openurl(URL: str) -> str:
|
61 |
+
html = f"<a href={URL} target=_blank>{URL}</a>"
|
62 |
+
return (html)
|
63 |
+
|
64 |
+
with gr.Blocks() as demo:
|
65 |
+
gr.Markdown("<h1><center>🥫Datasets🎨</center></h1>")
|
66 |
+
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://paperswithcode.com/datasets?q=mental&v=lst&o=newest">Mental</a>. <a href="https://paperswithcode.com/datasets?q=behavior&v=lst&o=newest">Behavior</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> """)
|
67 |
+
|
68 |
+
splits_data = gr.State()
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
dataset_name = gr.Dropdown(label="Dataset", interactive=True)
|
72 |
+
config = gr.Dropdown(label="Subset", interactive=True)
|
73 |
+
split = gr.Dropdown(label="Split", interactive=True)
|
74 |
+
|
75 |
+
with gr.Row():
|
76 |
+
#filterleft = gr.Textbox(label="First Column Filter",placeholder="Filter Column 1")
|
77 |
+
URLcenter = gr.Textbox(label="Dataset URL", placeholder="URL")
|
78 |
+
btn = gr.Button("Use Dataset")
|
79 |
+
#URLoutput = gr.Textbox(label="Output",placeholder="URL Output")
|
80 |
+
URLoutput = gr.HTML(label="Output",placeholder="URL Output")
|
81 |
+
|
82 |
+
with gr.Row():
|
83 |
+
dataset = gr.DataFrame(wrap=True, interactive=True)
|
84 |
+
|
85 |
+
demo.load(get_valid_datasets, inputs=None, outputs=[dataset_name])
|
86 |
+
|
87 |
+
dataset_name.change(update_configs, inputs=[dataset_name], outputs=[config, splits_data])
|
88 |
+
config.change(update_splits, inputs=[config, splits_data], outputs=[split, dataset])
|
89 |
+
split.change(update_dataset, inputs=[split, config, dataset_name], outputs=[dataset])
|
90 |
+
|
91 |
+
dataset_name.change(update_URL, inputs=[split, config, dataset_name], outputs=[URLcenter])
|
92 |
+
|
93 |
+
btn.click(openurl, [URLcenter], URLoutput)
|
94 |
+
|
95 |
+
demo.launch(debug=True)
|
96 |
+
|
97 |
+
# original: https://huggingface.co/spaces/freddyaboulton/dataset-viewer -- Freddy thanks! Your examples are the best.
|
98 |
+
# playlist on Gradio and Mermaid: https://www.youtube.com/watch?v=o7kCD4aWMR4&list=PLHgX2IExbFosW7hWNryq8hs2bt2aj91R-
|
99 |
+
# 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_1Ni2TubaA0CU2Bnt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