Running notebooks banned by Google Colab TOS or SD webui in colab without restrictions

"1boy, brown_hair, glasses, hat, looking_at_viewer, male_focus, short_hair, solo" - Deepbooru

“1boy, brown_hair, glasses, hat, looking_at_viewer, male_focus, short_hair, solo” – Deepbooru

Warning: Ahead of you is a short guide on running webui in a colab after April 2023, when this behavior became deprecated by google. If you are a man of principle and condemn omezhki who use gifts from google for their own selfish purposes – then you will not see anything interesting.

Derivatives Stable Diffusion gained immense popularity, which could not bypass the load of servers Google Colabwhich they provided free of charge to ML enthusiasts.

I own, though not the weakest card on the current market, but it belongs to the red vendor. This complicates the local way to run neural networks on it with pipeline.to(“cuda”) to dark sacrificial rituals called PlaidML. However, I want to enter the role of a regular consumer, forget about what is hidden behind the phrase “use neural networks” and just write “1girl…” “Astronaut in a ocean” – and get an image of an astronaut drowning in a puddle.

However, a huge online on Google servers, associated with an infinite number of otakuThose who wanted to draw anime characters for free to their taste and color could not go unnoticed, as a result, the restrictions were not long in coming (in fact, they were forced – almost half a year).

In general, a couple of months ago, a fad about different Webuis appeared in the rules for using Colab. But we are experienced users, we know that not caught is not a thief. However, the Almighty forces send pop-up windows, thereby forbidding us to even think about breaking the rules!

hello world!

hello world!

Thanks for the warning, I'm already canceling!

Thanks for the warning, I’m already canceling!

The consequences of rejecting this Warnings like this: The runtime crashes after a short period of time after startup.

I’m caught, I guess as a thief… Right?

Oh!  what is this - banwords?

Oh! what is this – banwords?

Surely such a large company could not be deceived by renaming files, right?

As you already understood – yes it could. And not only did we understand this, but the authors of the Stable-Diffusion-webui assemblies solved the problem at the root.

They began to name the folders not stable-diffusion-webui A sd-webui

As you understand, the topic worked for literally a week and the responsible people from Google stopped the indecency for the second time – they added sd-webui into banwords.

Time passed, but the finished solution was still not googled … It would seem that use the id generated on the go, publish your assemblies, at least under a different name – there are a lot of solutions to the problem. Why hasn’t anyone posted a finished notebook? Are there pitfalls?

A few months after the introduction of restrictions, I decided to write the desired functionality myself. And you know – it took me 10 minutes on the strength.

Bypassing Restrictions

Well, if the whole security check of the executed cell in colab comes down to finding a substring, then the solution suggests itself – obfuscation. I originally implemented this, but there is a problem: you need to run the notepad code with some analogue exec(), however, in a notepad we write on Ipython (hereinafter: .ipy), therefore exec crashes, seeing the very first syntax from Ipy. But Ipy would not be so cool if he could not be translated into a normal .py one library.

!pip install jupyter
!pip install nbconvert
!jupyter nbconvert "tmp.ipynb" --to python

And then I realized – I don’t need any obfuscation. you can just run invalid code from an .ipynb file and no one will suspect anything. Remains:

  • throw our webui assembly into the colab as an .ipynb file

  • apply translator .ipynb > .py on it

  • in Ipython environment read and run .py with regular exec()

from google.colab import files
name, cont=list(files.upload().items())[0] # Загрузка недопустимого блокнота

with open("tmp.ipynb","w") as f: f.write(cont.decode()) # Запись его в файл

!pip install jupyter
!pip install nbconvert                      # Перевод из .ipynb файла в .py файл
!jupyter nbconvert "tmp.ipynb" --to python

with open("tmp.py","r") as f: exec(f.read())  # Чтение и запуск .py

after running these 7 lines of code, cell prompts us to load our “invalid” notepad.

we see such a file picker

we see such a file picker

We throw here the pre-downloaded webui stable diffusion for the colab and it launches it without attracting the attention of the google ban machine.

I hope this short guide will help someone in launching their favorite checkpoint without straining for local hardware.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *