Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to read from Google Drive when running in Colab #100

Open
marcrasi opened this issue Apr 9, 2020 · 4 comments
Open

ability to read from Google Drive when running in Colab #100

marcrasi opened this issue Apr 9, 2020 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@marcrasi
Copy link
Contributor

marcrasi commented Apr 9, 2020

It would be nice to read from Google Drive when running Swift in Colab.

You can do this in Python Colab: https://colab.research.google.com/notebooks/io.ipynb. So the obvious thing to try is to use Swift's Python interop to Python.import the necessary libraries. Unfortunately, this does not work because the Python library prompts the user for an authentication key with an interactive text widget, and the Swift Python interop does not support interactive widgets.

So the right solution may be to modify the Python library so that you can pass it the authentication key directly instead of needing to paste it into a text widget. See here for a bit more detail about how it might be done: https://forums.fast.ai/t/python-textfield-output-not-working/51000/5?u=marcrasi

@marcrasi marcrasi added the help wanted Extra attention is needed label Apr 9, 2020
@mikkeyboi
Copy link
Contributor

mikkeyboi commented Apr 10, 2020

Throwing some ideas out there, but an approach similar to using Kaggle might be worth looking into (API token as JSON file). If users can't load the token via an interactive widget, they can use environment variables to specify its path, and then proceed to download their datasets. If this works, it could be an alternative.

For Google Drive, maybe a method from OAuth2 can be used. Would it be reasonable to: run a cell, browser tab opens, credentials are entered, copy token and paste it back to the cell?

Another way (seems kinda hacky) is to use cookiestxt (https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg), by storing the authenticated session in your browser, uploading it to the Colab session, and loading the cookies when retrieving the files from Drive.

Edit: Seems like even if any of these methods work, you'll still need to have a window of your drive contents open and probably can't write to the drive. Maybe getting PyDrive or something similar to work is a better idea.
Edit2: Realized you basically said the same thing in the fastai forum post. I'm going to give that a try.

@mikkeyboi
Copy link
Contributor

Have you tried using the method outlined by Conwyn here: https://forums.fast.ai/t/python-textfield-output-not-working/51000/12

@marcrasi
Copy link
Contributor Author

Thanks for the ideas! There were some questions on the swift@tensorflow.org mailing list about how to do this, so I just sent an email to the list letting everyone know that there are some new ideas here :)

@philipturner
Copy link
Contributor

I solved this problem! The solution was to allow Swift-Colab to switch between Swift mode and Python mode. In Python mode, execute the code that mounts Google Drive and uses an interactive text widget. Then, switch to Swift mode and restart the runtime. I was able to call %system ls "/content/drive/My Drive/Colab Notebooks" and it worked.

At the time of making this comment, my solution hasn't been implemented into upstream Swift-Colab yet. It will be possible by the 2.0 release, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants