Unverified Commit 3e0fe3cf authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Colab button (#6389)

* Add colab button

* Add colab link for tutorials
parent 79588e6f
/* Our DOM objects */ /* Our DOM objects */
/* Colab dropdown */
.colab-dropdown {
position: relative;
display: inline-block;
}
.colab-dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 117px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.colab-dropdown-content button {
color: #6670FF;
background-color: #f9f9f9;
font-size: 12px;
border: none;
min-width: 117px;
padding: 5px 5px;
text-decoration: none;
display: block;
}
.colab-dropdown-content button:hover {background-color: #eee;}
.colab-dropdown:hover .colab-dropdown-content {display: block;}
/* Version control */ /* Version control */
.version-button { .version-button {
......
...@@ -21,6 +21,17 @@ const versionMapping = { ...@@ -21,6 +21,17 @@ const versionMapping = {
"v1.1.0": "v1.1.0", "v1.1.0": "v1.1.0",
"v1.0.0": "v1.0.0" "v1.0.0": "v1.0.0"
} }
// The page that have a notebook and therefore should have the open in colab badge.
const hasNotebook = [
"benchmarks",
"multilingual",
"perplexity",
"preprocessing",
"quicktour",
"task_summary",
"tokenizer_summary",
"training"
];
function addIcon() { function addIcon() {
const huggingFaceLogo = "https://huggingface.co/landing/assets/transformers-docs/huggingface_logo.svg"; const huggingFaceLogo = "https://huggingface.co/landing/assets/transformers-docs/huggingface_logo.svg";
...@@ -82,6 +93,25 @@ function addGithubButton() { ...@@ -82,6 +93,25 @@ function addGithubButton() {
document.querySelector(".wy-side-nav-search .icon-home").insertAdjacentHTML('afterend', div); document.querySelector(".wy-side-nav-search .icon-home").insertAdjacentHTML('afterend', div);
} }
function addColabLink() {
const parts = location.toString().split('/');
const pageName = parts[parts.length - 1].split(".")[0];
if (hasNotebook.includes(pageName)) {
const linksColab = `
<div class="colab-dropdown">
<img alt="Open In Colab" src="https://colab.research.google.com/assets/colab-badge.svg">
<div class="colab-dropdown-content">
<button onclick=" window.open('https://colab.research.google.com/github/sgugger/test_nbs/blob/master/${pageName}.ipynb')">Mixed</button>
<button onclick=" window.open('https://colab.research.google.com/github/sgugger/test_nbs/blob/master/pytorch/${pageName}.ipynb')">PyTorch</button>
<button onclick=" window.open('https://colab.research.google.com/github/sgugger/test_nbs/blob/master/tensorflow/${pageName}.ipynb')">TensorFlow</button>
</div>
</div>`
const leftMenu = document.querySelector(".wy-breadcrumbs-aside")
leftMenu.innerHTML = linksColab + '\n' + leftMenu.innerHTML
}
}
function addVersionControl() { function addVersionControl() {
// To grab the version currently in view, we parse the url // To grab the version currently in view, we parse the url
const parts = location.toString().split('/'); const parts = location.toString().split('/');
...@@ -255,6 +285,7 @@ function onLoad() { ...@@ -255,6 +285,7 @@ function onLoad() {
addGithubButton(); addGithubButton();
parseGithubButtons(); parseGithubButtons();
addHfMenu(); addHfMenu();
addColabLink();
platformToggle(); platformToggle();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment