Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gradio to work on kaggle #3101

Merged
merged 4 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ def reverse(text):
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
Expand All @@ -1405,7 +1406,7 @@ def reverse(text):
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
)

Expand Down
6 changes: 6 additions & 0 deletions gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
format_ner_list,
get_local_ip_address,
ipython_check,
kaggle_check,
launch_analytics,
readme_to_html,
sanitize_list_for_csv,
Expand Down Expand Up @@ -103,6 +104,31 @@ def test_readme_to_html_doesnt_crash_on_connection_error(self, mock_get):
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
Expand Down