Spaces:
Running
Running
add filters
Browse files
app.py
CHANGED
|
@@ -34,23 +34,30 @@ def parse_notebook(filter_options):
|
|
| 34 |
reset_tmp_folder()
|
| 35 |
|
| 36 |
found_notebook = False
|
| 37 |
-
counter = 0
|
| 38 |
while not found_notebook:
|
| 39 |
-
counter+=1
|
| 40 |
-
print(counter, filter_options)
|
| 41 |
notebook_data = next(ds_iter)
|
| 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)
|
|
@@ -68,7 +75,7 @@ def parse_notebook(filter_options):
|
|
| 68 |
|
| 69 |
with gr.Blocks() as demo:
|
| 70 |
gr.Markdown("# Kaggle Notebooks")
|
| 71 |
-
filter_options = gr.Radio(["none",
|
| 72 |
|
| 73 |
button = gr.Button("Show next!")
|
| 74 |
file = gr.File()
|
|
|
|
| 34 |
reset_tmp_folder()
|
| 35 |
|
| 36 |
found_notebook = False
|
|
|
|
| 37 |
while not found_notebook:
|
|
|
|
|
|
|
| 38 |
notebook_data = next(ds_iter)
|
| 39 |
notebook_string = notebook_data["text"]
|
| 40 |
notebook_id = notebook_data["id"].split("/")[-1]
|
| 41 |
|
| 42 |
if filter_options == "none":
|
| 43 |
found_notebook = True
|
| 44 |
+
elif filter_options == ">10MB":
|
| 45 |
+
if len(notebook_string)>10 * 1024 * 1024:
|
| 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 == ">100KB":
|
| 51 |
+
if len(notebook_string)>100 * 1024:
|
| 52 |
+
found_notebook = True
|
| 53 |
+
elif filter_options == ">10KB":
|
| 54 |
+
if len(notebook_string)>10 * 1024:
|
| 55 |
+
found_notebook = True
|
| 56 |
+
# too slow
|
| 57 |
elif filter_options == "has outputs":
|
| 58 |
notebook_parsed = nbformat.reads(notebook_string, as_version=4)
|
| 59 |
(notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
|
| 60 |
+
if len(resources["outputs"])>0:
|
| 61 |
found_notebook = True
|
| 62 |
|
| 63 |
out_path = os.path.join(TMP_DIR, notebook_id)
|
|
|
|
| 75 |
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
gr.Markdown("# Kaggle Notebooks")
|
| 78 |
+
filter_options = gr.Radio(["none",">10KB", ">100KB", ">1MB", ">10MB"], value="none", label="Notebook filters", info="A lot of notebooks are short or have the outputs stripped - filters help finding interesting ones."),
|
| 79 |
|
| 80 |
button = gr.Button("Show next!")
|
| 81 |
file = gr.File()
|