Enable gradio to work on kaggle (#3101)

* enable share kaggle

* Add test

* CHANGELOG

* Add image to changelog
This commit is contained in:
Freddy Boulton 2023-02-01 11:53:53 -05:00 committed by GitHub
parent 4d94d4b3a5
commit 42ad0cbe45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 1 deletions

View File

@ -12,6 +12,14 @@ Previously photos uploaded via iOS would be rotated after processing. This has b
#### After
![image](https://user-images.githubusercontent.com/41651716/215846554-e41773ed-70f0-491a-9952-6a18babf91ef.png)
### Run on Kaggle kernels 🧪
A share link will automatically be created when running on Kaggle kernels (notebooks) so that
the front-end is properly displayed.
![image](https://user-images.githubusercontent.com/41651716/216104254-2cf55599-449c-436c-b57e-40f6a83f9eee.png)
By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3101](https://github.com/gradio-app/gradio/pull/3101)
## Bug Fixes:
- Fix change event listener for JSON, HighlightedText, Chatbot by [@aliabid94](https://github.com/aliabid94) in [PR 3095](https://github.com/gradio-app/gradio/pull/3095)

View File

@ -1383,6 +1383,7 @@ class Blocks(BlockContext):
self.server = server
self.is_running = True
self.is_colab = utils.colab_check()
self.is_kaggle = utils.kaggle_check()
self.protocol = (
"https"
if self.local_url.startswith("https") or self.is_colab
@ -1405,7 +1406,7 @@ class Blocks(BlockContext):
share
if share is not None
else True
if self.is_colab and self.enable_queue
if (self.is_colab and self.enable_queue) or self.is_kaggle
else False
)

View File

@ -189,6 +189,12 @@ def colab_check() -> bool:
return is_colab
def kaggle_check() -> bool:
return bool(
os.environ.get("KAGGLE_KERNEL_RUN_TYPE") or os.environ.get("GFOOTBALL_DATA_DIR")
)
def ipython_check() -> bool:
"""
Check if interface is launching from iPython (not colab)

View File

@ -29,6 +29,7 @@ from gradio.utils import (
format_ner_list,
get_local_ip_address,
ipython_check,
kaggle_check,
launch_analytics,
readme_to_html,
sanitize_list_for_csv,
@ -103,6 +104,31 @@ class TestUtils:
def test_readme_to_html_correct_parse(self):
readme_to_html("https://github.com/gradio-app/gradio/blob/master/README.md")
def test_kaggle_check_false(self):
assert not kaggle_check()
def test_kaggle_check_true_when_run_type_set(self):
with mock.patch.dict(
os.environ, {"KAGGLE_KERNEL_RUN_TYPE": "Interactive"}, clear=True
):
assert kaggle_check()
def test_kaggle_check_true_when_both_set(self):
with mock.patch.dict(
os.environ,
{"KAGGLE_KERNEL_RUN_TYPE": "Interactive", "GFOOTBALL_DATA_DIR": "./"},
clear=True,
):
assert kaggle_check()
def test_kaggle_check_false_when_neither_set(self):
with mock.patch.dict(
os.environ,
{"KAGGLE_KERNEL_RUN_TYPE": "", "GFOOTBALL_DATA_DIR": ""},
clear=True,
):
assert not kaggle_check()
class TestIPAddress:
@pytest.mark.flaky