Spaces:
Running
Running
File size: 969 Bytes
7924d77 1f9efe8 7924d77 1f9efe8 7924d77 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 |
import gradio as gr
from datasets import load_dataset
import nbformat
from nbconvert import HTMLExporter
# 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(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)
return notebook_body
with gr.Blocks() as demo:
gr.Markdown("# Kaggle Notebooks")
button = gr.Button("Get 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() |