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

Add Gradio interface for pulling Kaggle kernels and implement kernel download functionality

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- import os, json, pathlib, tempfile, datetime
3
  from typing import List, Dict, Optional
4
 
5
  from dotenv import load_dotenv
@@ -65,6 +65,16 @@ def search_kernels(query: str, max_results: int = 20) -> List[Dict]:
65
  )
66
  return out
67
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  search_iface = gr.Interface(
70
  fn=search_datasets,
@@ -77,6 +87,17 @@ search_iface = gr.Interface(
77
  description="Resturns a JSON array of dataset metadata."
78
  )
79
 
 
 
 
 
 
 
 
 
 
 
 
80
  list_files_iface = gr.Interface(
81
  fn=list_files,
82
  inputs=gr.Textbox(label="Dataset slug", placeholder="zalando-research/fashionmnist"),
@@ -108,8 +129,8 @@ search_kernels_iface = gr.Interface(
108
  )
109
 
110
  demo = gr.TabbedInterface(
111
- [search_iface, list_files_iface, download_file_iface, search_kernels_iface],
112
- tab_names=["Search Datasets", "Files", "Download File", "Search Kernels"],
113
  )
114
 
115
  def _bootstrap_kaggle_credentials():
 
1
  import gradio as gr
2
+ import os, json, pathlib, tempfile, datetime, shutil
3
  from typing import List, Dict, Optional
4
 
5
  from dotenv import load_dotenv
 
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
+
72
+ zip_path = shutil.make_archive(
73
+ base_name=os.path.join(tmp_dir, "kernel"),
74
+ format = "zip",
75
+ root_dir=tmp_dir,
76
+ )
77
+ return zip_path
78
 
79
  search_iface = gr.Interface(
80
  fn=search_datasets,
 
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",
95
+ ),
96
+ outputs=gr.File(label="Downlaod .zip"),
97
+ title="pull kaggle kernel",
98
+ description="Downlaods the notebook or script kernel and returns a ZIP archive."
99
+ )
100
+
101
  list_files_iface = gr.Interface(
102
  fn=list_files,
103
  inputs=gr.Textbox(label="Dataset slug", placeholder="zalando-research/fashionmnist"),
 
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():