lvwerra HF Staff commited on
Commit
a386c0e
·
1 Parent(s): 415d76d
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -23,41 +23,38 @@ def reset_tmp_folder():
23
 
24
  def parse_notebook():
25
  reset_tmp_folder()
26
-
27
  notebook_data = next(ds_iter)
28
  notebook_string = notebook_data["text"]
29
  notebook_id = notebook_data["id"].split("/")[-1]
 
30
 
31
  # Save the notebook string to a file
32
- with open(os.path.join(TMP_DIR, notebook_id), 'w') as f:
33
  f.write(notebook_string)
34
 
35
  notebook_parsed = nbformat.reads(notebook_string, as_version=4)
36
  (notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
37
 
38
  print("Resources:", resources["outputs"])
39
- return notebook_body
40
 
41
- def download_notebook():
42
- for filename in os.listdir(TMP_DIR):
43
- if filename.endswith('.ipynb'):
44
- path = os.path.join(TMP_DIR, filename)
45
- print(path)
46
- return path
47
 
48
  with gr.Blocks() as demo:
49
  gr.Markdown("# Kaggle Notebooks")
50
 
51
  with gr.Row():
52
  button = gr.Button("Show next!")
53
- button_download = gr.Button("Download notebook")
54
 
55
  with gr.Row():
56
  with gr.Column():
57
  html = gr.HTML("")
 
 
 
 
58
 
59
- button.click(fn=parse_notebook, inputs=[], outputs=[html])
60
- button_download.click(fn=download_notebook, inputs=[], outputs=[])
61
- demo.load(fn=parse_notebook, inputs=[], outputs=[html])
62
 
63
  demo.launch()
 
23
 
24
  def parse_notebook():
25
  reset_tmp_folder()
 
26
  notebook_data = next(ds_iter)
27
  notebook_string = notebook_data["text"]
28
  notebook_id = notebook_data["id"].split("/")[-1]
29
+ out_path = os.path.join(TMP_DIR, notebook_id)
30
 
31
  # Save the notebook string to a file
32
+ with open(out_path, 'w') as f:
33
  f.write(notebook_string)
34
 
35
  notebook_parsed = nbformat.reads(notebook_string, as_version=4)
36
  (notebook_body, resources) = html_exporter.from_notebook_node(notebook_parsed)
37
 
38
  print("Resources:", resources["outputs"])
39
+ return notebook_body, out_path
40
 
 
 
 
 
 
 
41
 
42
  with gr.Blocks() as demo:
43
  gr.Markdown("# Kaggle Notebooks")
44
 
45
  with gr.Row():
46
  button = gr.Button("Show next!")
47
+ #button_download = gr.Button("Download notebook")
48
 
49
  with gr.Row():
50
  with gr.Column():
51
  html = gr.HTML("")
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ file = gr.File()
56
 
57
+ button.click(fn=parse_notebook, inputs=[], outputs=[html, file])
58
+ demo.load(fn=parse_notebook, inputs=[], outputs=[html, file])
 
59
 
60
  demo.launch()