Skip to content

Commit

Permalink
Set share=True for all Gradio apps in Colab by default (#5767)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
abidlabs and gradio-pr-bot committed Oct 2, 2023
1 parent 8f0fed8 commit caf6d9c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/yummy-mice-start.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Set share=True for all Gradio apps in Colab by default
2 changes: 1 addition & 1 deletion gradio/blocks.py
Expand Up @@ -2080,7 +2080,7 @@ def reverse(text):
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"
Expand Down
6 changes: 3 additions & 3 deletions test/test_blocks.py
Expand Up @@ -65,11 +65,11 @@ def test_set_share_in_colab(self, mock_colab_check, mock_setup_tunnel):
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
Expand Down
8 changes: 0 additions & 8 deletions test/test_interfaces.py
Expand Up @@ -103,14 +103,6 @@ def test_block_thread(self, mock_sleep):
"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):
Expand Down

0 comments on commit caf6d9c

Please sign in to comment.