Skip to content

Commit 33bd71c

Browse files
Merge pull request #1033 from julien-c/open-from-huggingface
Add provider for huggingface.co: Very basic `uri_rewrites`
2 parents df13998 + 958fb12 commit 33bd71c

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Providers are sources of notebooks and directories of notebooks and directories.
159159
- `url`
160160
- `gist`
161161
- `github`
162+
- `huggingface`
162163
- `local`
163164

164165
#### Writing a new Provider

nbviewer/providers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
default_rewrites = [
1313
"nbviewer.providers.{}".format(prov)
14-
for prov in ["gist", "github", "dropbox", "url"]
14+
for prov in ["gist", "github", "dropbox", "huggingface", "url"]
1515
]
1616

1717

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .handlers import uri_rewrites
2+
3+
__all__ = ["uri_rewrites"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (C) Jupyter Development Team
3+
#
4+
# Distributed under the terms of the BSD License. The full license is in
5+
# the file COPYING, distributed as part of this software.
6+
# -----------------------------------------------------------------------------
7+
8+
9+
def uri_rewrites(rewrites=[]):
10+
return rewrites + [
11+
(
12+
r"^https://huggingface.co/(.+?)/blob/(.+?)$",
13+
"/urls/huggingface.co/{0}/resolve/{1}",
14+
)
15+
]

nbviewer/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
type="text"
1919
name="gistnorurl"
2020
autofocus="autofocus"
21-
placeholder="URL | GitHub username | GitHub username/repo | Gist ID"/>
21+
placeholder="URL | GitHub username | GitHub username/repo | Gist ID | HuggingFace URL"/>
2222
<span class="input-group-btn">
2323
<button class="btn btn-default" type="submit" type="button">
2424
Go!

nbviewer/tests/test_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ def test_transform_ipynb_uri():
4545
"https://www.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb?dl=1",
4646
"/urls/dl.dropbox.com/sh/mhviow274da2wly/CZKwRRcA0k/nested/furthernested/User%2520Interface.ipynb",
4747
),
48+
# HuggingFace urls
49+
(
50+
"https://huggingface.co/pceiyos/fake_news_detection_nlp/blob/main/Fake_News_Classificaton.ipynb",
51+
"/urls/huggingface.co/pceiyos/fake_news_detection_nlp/resolve/main/Fake_News_Classificaton.ipynb",
52+
),
53+
(
54+
"https://huggingface.co/spaces/NimaBoscarino/climategan/blob/main/notebooks/plot_metrics.ipynb",
55+
"/urls/huggingface.co/spaces/NimaBoscarino/climategan/resolve/main/notebooks/plot_metrics.ipynb",
56+
# This ClimateGAN notebook is served over LFS (as the file is 17.1 MB)
57+
),
58+
(
59+
"https://huggingface.co/spaces/dalle-mini/dalle-mini/blob/63679e968109278c5f0169100b1755bbda9f4bc6/tools/inference/inference_pipeline.ipynb",
60+
"/urls/huggingface.co/spaces/dalle-mini/dalle-mini/resolve/63679e968109278c5f0169100b1755bbda9f4bc6/tools/inference/inference_pipeline.ipynb",
61+
# This Dall-e mini notebook is hosted from a specific revision (= git commit)
62+
),
4863
# URL
4964
("https://example.org/ipynb", "/urls/example.org/ipynb"),
5065
("http://example.org/ipynb", "/url/example.org/ipynb"),

0 commit comments

Comments
 (0)