Spaces:
Running
Running
initial version
Browse files
app.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from datasets import load_dataset
|
| 3 |
+
import nbformat
|
| 4 |
+
from nbconvert import HTMLExporter
|
| 5 |
|
| 6 |
+
# Instantiate the exporter. We use the `classic` template for now; we'll get into more details
|
| 7 |
+
# later about how to customize the exporter further.
|
| 8 |
+
html_exporter = HTMLExporter(template_name="classic")
|
| 9 |
|
| 10 |
+
ds = load_dataset("data-agents/kaggle-notebooks", split="train", streaming=True)
|
| 11 |
+
ds_iter = iter(ds)
|
| 12 |
+
|
| 13 |
+
def parse_notebook():
|
| 14 |
+
notebook_string = next(ds_iter)["text"]
|
| 15 |
+
notebook_parsed = nbformat.reads(notebook_string, as_version=4)
|
| 16 |
+
(notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
|
| 17 |
+
return notebook_body
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# Kaggle Notebooks")
|
| 22 |
+
button = gr.Button("Get next!")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
html = gr.HTML("")
|
| 27 |
+
|
| 28 |
+
button.click(fn=parse_notebook, inputs=[], outputs=[html])
|
| 29 |
+
demo.load(fn=parse_notebook, inputs=[], outputs=[html])
|
| 30 |
+
demo.launch()
|