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

Allow config to include non-pickle-able values #7415

Merged
merged 5 commits into from Feb 14, 2024
Merged

Allow config to include non-pickle-able values #7415

merged 5 commits into from Feb 14, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 14, 2024

Closes: #7412

As part of the recent changes around root, I added a step which deep-copied the config. This prevented the config from including any objects that could not be pickled. I've refactored the code so that we do not need to deepcopy the config any more. As an added bonus, this should mostly eliminate the performance issues caused by #7374

Simple repro:

import gradio as gr

my_dict = {'a': 1, 'b': 2, 'c': 3}

with gr.Blocks() as demo:
    j = gr.JSON(my_dict.keys())
    
demo.launch()

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 14, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/5301c417716020bf57c52beefc48de10c4254993/gradio-4.18.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@5301c417716020bf57c52beefc48de10c4254993#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 14, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Allow config to include non-pickle-able values

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

gradio/routes.py Outdated
config = add_root_url(config, root_path)
config = app.get_blocks().config
previous_root = config.get("root", None)
if previous_root is None or previous_root != root:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change in this PR being that we no longer need to traverse the config if the root has not change

config = copy.deepcopy(app.get_blocks().config)
config["root"] = root_path
config = add_root_url(config, root_path)
config = app.get_blocks().config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be worth abstracting this into a helper function with docstring explaining the logix even though it's only used in two places to make the code more "documentable". Nit though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do

@abidlabs
Copy link
Member Author

Thanks @freddyaboulton for the review! I've made the suggested changes and am putting this on auto-merge

@abidlabs abidlabs enabled auto-merge (squash) February 14, 2024 17:37
@abidlabs abidlabs merged commit 4ab399f into main Feb 14, 2024
7 checks passed
@abidlabs abidlabs deleted the pickle-error branch February 14, 2024 17:43
@pngwn pngwn mentioned this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating to Gradio 4.18.0 causing TypeError: cannot pickle 'dict_keys' object
3 participants