What is Google Colab?
Google Colab (or Colaboratory or Colab) is an online notebook running on Google Cloud which allows you write and execute Python on browser without using resources of your computer. It can be considered as an online Jupyter Notebook, i.e. it allows multi programming languages: Markdown, HTML, Latex, Python, R, … . You may visit the origin of this post in Colab by simply clicking on the badge Open in Colab at the begining of the post. Hope you enjoy it!
- You may type maths expression or run your Python code
2+2
4
- You may plot
import numpy as np
from matplotlib import pyplot as plt
ys = 200 + np.random.randn(100)
x = [x for x in range(len(ys))]
plt.plot(x, ys, '-')
plt.fill_between(x, ys, 195, where=(ys > 195), facecolor='g', alpha=0.6)
plt.title("Sample Visualization")
plt.show()
- You may import probably all kinds of packages, e.g.
torch
. However, in Binder you sometimes can't even importnumpy
.
import torch
print("import torch successfully")
import torch successfully
How to bring your notebook to blog post?
The naive idea is to use Jupyter Notebook opens your notebook and export it as .html
file. However, you will encounter the size-inconsistency between the post and your website. How to fix it?
Solution 1.
The following is a temporary solution, it's not very elegant, but at least it works. If you already have a notebook go straightforward to step 2. The strategy is to convert your notebook being an .ipynb
to .md
and then to .html
a format suitable for our blog post.
- Go to this Google Colab change the contents and the codes as you want. In the tab
File
, download it as an.ipynb
file. - Go to Github and upload it to your publish repository.
- Go to Binder, past the link of your repository and the press the
launch
button. Open the.ipynb
file. A Jupyter interface will be appear. In tabFile
, download it as a.md
file. - Copy the content of the
.md
file (you may copy it by uploading and then opening it using Google Drive). - Go to StackEdit and past its content to a new file created in StackEdit. Export the file as an
.html
file. - Go to Blogger, copy the content of your
.html
file and past it to your Blog post. Note that you have to manage the images by hand.
I know that it is quite complicated as it requires a lot of steps as Colab does not support export .md
and .html
files. Of course, we can make the steps shorter by creating a notebook in Jupyter directly and then export it to a .md
. Above general process is useful in some cases, e.g. cannot import torch
in Jupyter. I hope I will find a simpler method in the comming time.
Solution 2.
... to be updated