Roobick commited on
Commit
86ffe1f
·
1 Parent(s): 27a857e

Refactor file download functions and Gradio interfaces for clarity and consistency

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -26,7 +26,7 @@ def list_files(dataset_slug: str) -> List[Dict]:
26
  files = api.dataset_list_files(dataset_slug).files
27
  return [{"name": f.name, "size_mb": round(f.total_bytes / 1e6, 2)} for f in files]
28
 
29
- def download_file(dataset_slug: str, file_name: str):
30
  tmp_dir = tempfile.mkdtemp()
31
  api.dataset_download_file(dataset_slug, file_name, path=tmp_dir, quiet=False)
32
  zip_path = pathlib.Path(tmp_dir) / f"{file_name}"
@@ -65,7 +65,7 @@ def search_kernels(query: str, max_results: int = 20) -> List[Dict]:
65
  )
66
  return out
67
 
68
- def pull_kernel(kernel_ref: str) -> str:
69
  tmp_dir = tempfile.mkdtemp()
70
  api.kernels_pull(kernel_ref, path=tmp_dir, quiet=False)
71
 
@@ -87,8 +87,8 @@ search_iface = gr.Interface(
87
  description="Resturns a JSON array of dataset metadata."
88
  )
89
 
90
- pull_kernel_iface = gr.Interface(
91
- fn = pull_kernel,
92
  inputs=gr.Textbox(
93
  label="kernel reference",
94
  placeholder="e.g. username/notebook-name",
@@ -106,8 +106,8 @@ list_files_iface = gr.Interface(
106
  description="Given a dataset slug, returns its file list."
107
  )
108
 
109
- download_file_iface = gr.Interface(
110
- fn=download_file,
111
  inputs=[
112
  gr.Textbox(label="Dataset slug", placeholder="zalando-research/fashionmnist"),
113
  gr.Textbox(label="File name", placeholder="fashion-mnist_test.csv")
@@ -129,8 +129,8 @@ search_kernels_iface = gr.Interface(
129
  )
130
 
131
  demo = gr.TabbedInterface(
132
- [search_iface, list_files_iface, download_file_iface, search_kernels_iface, pull_kernel_iface],
133
- tab_names=["Search Datasets", "Files", "Download File", "Search Kernels", "Pull kernel"],
134
  )
135
 
136
  def _bootstrap_kaggle_credentials():
 
26
  files = api.dataset_list_files(dataset_slug).files
27
  return [{"name": f.name, "size_mb": round(f.total_bytes / 1e6, 2)} for f in files]
28
 
29
+ def download_dataset_file(dataset_slug: str, file_name: str):
30
  tmp_dir = tempfile.mkdtemp()
31
  api.dataset_download_file(dataset_slug, file_name, path=tmp_dir, quiet=False)
32
  zip_path = pathlib.Path(tmp_dir) / f"{file_name}"
 
65
  )
66
  return out
67
 
68
+ def download_kernel_notebook(kernel_ref: str) -> str:
69
  tmp_dir = tempfile.mkdtemp()
70
  api.kernels_pull(kernel_ref, path=tmp_dir, quiet=False)
71
 
 
87
  description="Resturns a JSON array of dataset metadata."
88
  )
89
 
90
+ download_kernel_iface = gr.Interface(
91
+ fn = download_kernel_notebook,
92
  inputs=gr.Textbox(
93
  label="kernel reference",
94
  placeholder="e.g. username/notebook-name",
 
106
  description="Given a dataset slug, returns its file list."
107
  )
108
 
109
+ download_dataset_iface = gr.Interface(
110
+ fn=download_dataset_file,
111
  inputs=[
112
  gr.Textbox(label="Dataset slug", placeholder="zalando-research/fashionmnist"),
113
  gr.Textbox(label="File name", placeholder="fashion-mnist_test.csv")
 
129
  )
130
 
131
  demo = gr.TabbedInterface(
132
+ [search_iface, list_files_iface, download_dataset_iface, search_kernels_iface, download_kernel_iface],
133
+ tab_names=["Search Datasets", "Files", "Download dataset", "Search Kernels", "Download kernels"],
134
  )
135
 
136
  def _bootstrap_kaggle_credentials():