diff --git a/README.md b/README.md index 2d20b6f..31094ac 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ add `--bore` to commandline options. add `--bore_url "URL"` for custom bore url. url without 'http://' and (optional) port. example: myboreserver.com or myboreserver.com:12345 +### googleusercontent + +add `--googleusercontent` to commandline options. It must be used with `--no-gradio-queue`, otherwise it will not work. + +If not in google colab, it will be ignored. + ----- ### Discord webhook diff --git a/preload.py b/preload.py index eb7455f..335e77c 100644 --- a/preload.py +++ b/preload.py @@ -38,6 +38,12 @@ def preload(parser: argparse.ArgumentParser): help="custom bore url. url without 'http://' and (optional) port. example: myboreserver.com or myboreserver.com:12345", ) + parser.add_argument( + "--googleusercontent", + action="store_true", + help="use googleusercontent, only available in the google colab. must be used with --no-gradio-queue", + ) + parser.add_argument( "--tunnel-webhook", type=str, help="discord webhook to send tunnel url to" ) diff --git a/scripts/googleusercontent.py b/scripts/googleusercontent.py new file mode 100644 index 0000000..e9281be --- /dev/null +++ b/scripts/googleusercontent.py @@ -0,0 +1,24 @@ +import os + +from discord_webhook import send_to_discord +from modules.shared import cmd_opts + + +is_colab = "COLAB_RELEASE_TAG" in os.environ or "COLAB_BACKEND_VERSION" in os.environ + +if is_colab and cmd_opts.googleusercontent: + print("googleusercontent detected, trying to connect...") + + if not getattr(cmd_opts, "no_gradio_queue", True): + msg = " * If without `--no-gradio-queue` option, it will not work on google colab." + print(msg) + + from google.colab.output import eval_js + + port = cmd_opts.port if cmd_opts.port else 7860 + js = "google.colab.kernel.proxyPort(" + str(port) + ", {'cache': false})" + tunnel_url = eval_js(js) + print(f" * Running on {tunnel_url}") + + if cmd_opts.tunnel_webhook: + send_to_discord(tunnel_url, cmd_opts.tunnel_webhook)