julien-c HF staff commited on
Commit
7eecb79
1 Parent(s): df87638

working version with some TODOs

Browse files
Files changed (2) hide show
  1. app.py +7 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -10,7 +10,7 @@ from starlette.requests import Request
10
  from starlette.routing import Route
11
 
12
  client = httpx.AsyncClient()
13
- html_exporter = HTMLExporter(template_name="classic")
14
 
15
 
16
  async def homepage(_):
@@ -25,6 +25,7 @@ async def convert(req: Request):
25
  url = req.query_params.get("url")
26
  if not url:
27
  raise HTTPException(400, "Param url is missing")
 
28
  r = await client.get(
29
  url,
30
  headers={"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"},
@@ -40,7 +41,7 @@ async def convert(req: Request):
40
  try:
41
  notebook_node: NotebookNode = nbformat.reads(
42
  r.text,
43
- as_version=4,
44
  )
45
  except nbformat.reader.NotJSONError:
46
  print(400, f"Notebook is not JSON ({url})")
@@ -56,7 +57,10 @@ async def convert(req: Request):
56
  )
57
 
58
  print(f"Input: nbformat v{notebook_node.nbformat}.{notebook_node.nbformat_minor}")
59
- return HTMLResponse("<strong>FOO</strong>")
 
 
 
60
 
61
 
62
  app = Starlette(
 
10
  from starlette.routing import Route
11
 
12
  client = httpx.AsyncClient()
13
+ html_exporter = HTMLExporter(template_name="lab")
14
 
15
 
16
  async def homepage(_):
 
25
  url = req.query_params.get("url")
26
  if not url:
27
  raise HTTPException(400, "Param url is missing")
28
+ print("\n===", url)
29
  r = await client.get(
30
  url,
31
  headers={"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"},
 
41
  try:
42
  notebook_node: NotebookNode = nbformat.reads(
43
  r.text,
44
+ as_version=nbformat.current_nbformat,
45
  )
46
  except nbformat.reader.NotJSONError:
47
  print(400, f"Notebook is not JSON ({url})")
 
57
  )
58
 
59
  print(f"Input: nbformat v{notebook_node.nbformat}.{notebook_node.nbformat_minor}")
60
+ body, _ = html_exporter.from_notebook_node(notebook_node)
61
+ # TODO(customize or simplify template?)
62
+ # TODO(also check source code for jupyter/nbviewer)
63
+ return HTMLResponse(body)
64
 
65
 
66
  app = Starlette(
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  httpx==0.23.3
2
  starlette==0.23.1
 
3
  nbconvert==7.2.8
4
  uvicorn==0.20.0
 
1
  httpx==0.23.3
2
  starlette==0.23.1
3
+ ipython==8.8.0
4
  nbconvert==7.2.8
5
  uvicorn==0.20.0