lvwerra HF Staff commited on
Commit
ac98601
·
1 Parent(s): 52cb009

add filters

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -30,7 +30,7 @@ def embed_figures(html_body, resources):
30
  html_body = html_body.replace(key, img_tag)
31
  return html_body
32
 
33
- def parse_notebook():
34
  reset_tmp_folder()
35
 
36
  found_notebook = False
@@ -42,8 +42,16 @@ def parse_notebook():
42
  notebook_string = notebook_data["text"]
43
  notebook_id = notebook_data["id"].split("/")[-1]
44
 
45
- if len(notebook_string)>1 * 1024 * 1024:
46
  found_notebook = True
 
 
 
 
 
 
 
 
47
 
48
  out_path = os.path.join(TMP_DIR, notebook_id)
49
 
@@ -60,12 +68,14 @@ def parse_notebook():
60
 
61
  with gr.Blocks() as demo:
62
  gr.Markdown("# Kaggle Notebooks")
 
 
63
  button = gr.Button("Show next!")
64
  file = gr.File()
65
  html = gr.HTML("")
66
 
67
 
68
- button.click(fn=parse_notebook, inputs=[], outputs=[html, file])
69
- demo.load(fn=parse_notebook, inputs=[], outputs=[html, file])
70
 
71
  demo.launch()
 
30
  html_body = html_body.replace(key, img_tag)
31
  return html_body
32
 
33
+ def parse_notebook(filter_options):
34
  reset_tmp_folder()
35
 
36
  found_notebook = False
 
42
  notebook_string = notebook_data["text"]
43
  notebook_id = notebook_data["id"].split("/")[-1]
44
 
45
+ if filter_options == "none":
46
  found_notebook = True
47
+ elif filter_options == ">1MB":
48
+ if len(notebook_string)>1 * 1024 * 1024:
49
+ found_notebook = True
50
+ elif filter_options == "has outputs":
51
+ notebook_parsed = nbformat.reads(notebook_string, as_version=4)
52
+ (notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
53
+ if len(resources)>0:
54
+ found_notebook = true
55
 
56
  out_path = os.path.join(TMP_DIR, notebook_id)
57
 
 
68
 
69
  with gr.Blocks() as demo:
70
  gr.Markdown("# Kaggle Notebooks")
71
+ filter_options = gr.Radio(["none", "has outputs", ">1MB"], label="Notebook filters", info="A lot of notebooks are short or have the outputs stripped - filters help finding interesting ones."),
72
+
73
  button = gr.Button("Show next!")
74
  file = gr.File()
75
  html = gr.HTML("")
76
 
77
 
78
+ button.click(fn=parse_notebook, inputs=[filter_options], outputs=[html, file])
79
+ demo.load(fn=parse_notebook, inputs=[filter_options], outputs=[html, file])
80
 
81
  demo.launch()