File size: 1,213 Bytes
7924d77
1f9efe8
 
 
3bd4bd2
 
 
 
 
7924d77
1f9efe8
 
3bd4bd2
7924d77
1f9efe8
 
 
 
 
 
 
3bd4bd2
1f9efe8
 
 
 
 
3bd4bd2
1f9efe8
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from datasets import load_dataset
import nbformat
from nbconvert import HTMLExporter
from traitlets.config import Config

# we want to export the outputs too:
config = Config()
config.HTMLExporter.preprocessors = ["nbconvert.preprocessors.ExtractOutputPreprocessor"]

#  Instantiate the exporter. We use the `classic` template for now; we'll get into more details
# later about how to customize the exporter further.
html_exporter = HTMLExporter(config=config, template_name="classic")

ds = load_dataset("data-agents/kaggle-notebooks", split="train", streaming=True)
ds_iter = iter(ds)

def parse_notebook():
    notebook_string = next(ds_iter)["text"]
    notebook_parsed = nbformat.reads(notebook_string, as_version=4)
    (notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
    print("Resources:", resources["outputs"])
    return notebook_body


with gr.Blocks() as demo:
    gr.Markdown("# Kaggle Notebooks")
    button = gr.Button("Show next!")

    with gr.Row():
        with gr.Column():
            html = gr.HTML("")

    button.click(fn=parse_notebook, inputs=[], outputs=[html])
    demo.load(fn=parse_notebook, inputs=[], outputs=[html])
demo.launch()