Set share=True for all Gradio apps in Colab by default (#5767)

* Set share=True for all Gradio apps in Colab by default

* add changeset

* fix tests

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Abubakar Abid 2023-10-02 12:51:56 -07:00 committed by GitHub
parent 8f0fed857d
commit caf6d9c0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 12 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Set share=True for all Gradio apps in Colab by default

View File

@ -2080,7 +2080,7 @@ Received outputs:
utils.launch_counter()
self.is_sagemaker = utils.sagemaker_check()
if share is None:
if self.is_colab and self.enable_queue:
if self.is_colab:
if not quiet:
print(
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n"

View File

@ -65,11 +65,11 @@ class TestBlocksMethods:
with gr.Blocks() as demo:
# self.share is False when instantiating the class
assert not demo.share
# share default is False, if share is None in colab and no queueing
# share default is True, if share is None in colab and queueing
demo.launch(prevent_thread_lock=True)
assert not demo.share
assert demo.share
demo.close()
# share becomes true, if share is None in colab with queueing
# share is also true, if share is None in colab with queueing
demo.queue()
demo.launch(prevent_thread_lock=True)
assert demo.share

View File

@ -103,14 +103,6 @@ class TestInterface:
"Keyboard interruption in main thread... closing server." in output
)
@mock.patch("gradio.utils.colab_check")
def test_launch_colab_share(self, mock_colab_check):
mock_colab_check.return_value = True
interface = Interface(lambda x: x, "textbox", "label")
_, _, share_url = interface.launch(prevent_thread_lock=True)
assert share_url is None
interface.close()
@mock.patch("gradio.utils.colab_check")
@mock.patch("gradio.networking.setup_tunnel")
def test_launch_colab_share_error(self, mock_setup_tunnel, mock_colab_check):