Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Google Colab ipynb to Github?

I'm on a Chromebook (stock setup), but relatively new to the whole coding business. Presently, I'm trying to gain familiarity with Google Colaboratory coupled to Google Drive to do data analysis anywhere.

My problem, then is this: Since I can access Github via !git automatically in Colab, I created a new repository and cloned it. But I can't add the .ipynb because !git status shows no changes/doesn't see the notebook I'm in as a file. How can I push the .ipynb from my Google Drive back to Github?

Basically, I hope to pull up Colab anywhere, play with my data, save the changes in the .ipynb, push to Github, and go elsewhere to keep playing with the data.

Manual copying likely would work, but is there a more elegant solution?

TIA!

like image 846
jaymullr Avatar asked Feb 09 '18 17:02

jaymullr


People also ask

How do I upload Ipynb to Google Colab?

How to open Google Colab. You can open a new Colab notebook from your Google Drive window or by visiting the Colab site. From the Colaboratory site, you can use the menu to upload an iPython notebook: This will upload the ipynb file that you downloaded before.


2 Answers

You have likely come up with a solution to this by now, but I see that there is now a "Save copy to Github" feature in Colab, quoted from this blog post:

You can also easily save a copy of your Colab notebook to Github by using File > Save a copy to Github…

like image 52
Dan Reia Avatar answered Sep 21 '22 02:09

Dan Reia


@jaymullr, have you managed to find your way?

Here is the tutorial how to easily setup your notebook from github to Google Colab using Clouderizer: Medium tutorial. Okay, maybe what you wanted is the other way around, google Colab to github. The exciting things is that using clouderizer allows you to do both! Sync your jupyter notebook, github, and Colab. My steps might seems rigorously long but it's actually really easy, one time setup for all. Here is how I do it (skip to Sync back to GitHub if you just wanna know the big picture of how):

Clouderizer for Google Colab Project

Prerequisites

  1. Sign Up for google/gmail account
  2. Sign up for Clouderizer account [link]
  3. Create a repository on your github and upload your project (all ipynb, py modules, and even dataset(zip it if < 1GB)) to your repo.

Setup Clouderizer Project

  1. Login to Clouderizer console. On first login, you will be prompted to link your Google Drive with Clouderizer. Follow on-screen instructions to do so. In case it doesn't prompt the link, you can configure your Google Drive by going to Clouderizer dashboard->sidebar menu->Clouderizer Drive. The Clouderizer will setup a folder called 'clouderizer' in your Google Drive to contain your ipynb project (be it Machine Learning or any)
  2. Go back to Clouderizer Dashboard. Then click new Project. As you follow the instruction, you can opt to load the whole github project that contains your ipynb work that you intend to upload to Google Colab.
  3. In step 5, you can include additional dataset you want to work on by specifying the URL for dataset (eg. from kaggle dataset URL). You can also opt and specify if you would like to refactor your project by having separate folder for dataset, main code/modules, and output files.
  4. Next, head to Google Colab/ create a Google Colab file anywhere in you Google Drive, then execute: !wget NS -content disposition 'https://to_whatever_link_you_get_to_console'
  5. Finally, go back to Clouderizer dashboard and check if your project environment is running already and synced to Google Colab. Then click on jupyter notebook icon in that dashboard, just right next to the title name of the project you give. Now, you can start doing your Machine Learning or whatever work you do as if you're doing it on local machine, then sync it immediately at Google Colab.
  6. Finally you will be able to verify if your .ipynb will work and able to import modules/datasets in Google Colab too. Just go back to Google Drive->clouderizer folder->your project. Then try to run and see if everything works as it is in jupyter notebook.

Sync back to github

  1. Nothing special here. Go back to Clouderizer jupyter notebook, open terminal in the root/top level directory and $git push origin master. That's it!

If you find my way interesting, hit upvote. However, this method might be too tedious at first. Let me know what you think! Clouderizer is free btw.

like image 26
Daniel Kurniadi Avatar answered Sep 18 '22 02:09

Daniel Kurniadi