Spaces:
Running
Running
| 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() |