gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Cleaning up the way data is processed for components

Open abidlabs opened this issue 1 year ago • 1 comments

There is a lot of redundant data processing code for each Component (more details below), which is problematic because: (1) bugs are introduced when some parts of the code are updated, but other parts are not (2) it's hard to understand how the data is preprocessed / postprocessed, thereby making it harder to understand the existing codebase as well as to contribute new components.

This PR eliminates the following redundancies and along the ways, fixes: #1194, fixes: #1721

  1. preprocess_example() being a special case of postprocess() for most components -- both functions takes a Python object (e.g. PIL image or path to image file) and serializes it (e.g. to base64 representation) so that it can be viewed in the browser. However, for file-based components, we do not serialize examples, but rather just include a reference to them, so this special case needs to be handled.
  2. serialize() and deserialize() being part of postprocess() and preprocess() respectively.

abidlabs avatar Aug 07 '22 21:08 abidlabs

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-1967-all-demos

github-actions[bot] avatar Aug 16 '22 16:08 github-actions[bot]

Thanks guys for the review! Will go through these and fix these tonight, please let me know if you find any other failing demos

abidlabs avatar Aug 16 '22 23:08 abidlabs

Hmm okay it looks like this breaks Interface.load for models loaded from the Hub. Will need to dive into this more deeply tomorrow

abidlabs avatar Aug 17 '22 06:08 abidlabs

Hi @freddyaboulton and @aliabid94, thanks for the initial review of the PR. I fixed the Interface.load() issue with the inference API and individually tested with all of the pipelines that we support. That issue should be fixed now.

If you could take one more pass before I merge this in, would really appreciate it!

abidlabs avatar Aug 18 '22 03:08 abidlabs

@abidlabs This is a heroic PR! So far I've just been finding little things that are broken from the refactor but I really like the approach you've taken so I think it's just a matter of making sure we don't accidentally break anything with the PR!

About to take off will continue reviewing later this afternoon!

freddyaboulton avatar Aug 18 '22 16:08 freddyaboulton

Thank you for reviewing so thoroughly @freddyaboulton!

abidlabs avatar Aug 18 '22 17:08 abidlabs

Great find @freddyaboulton and thanks for the tireless reviews! Will merge it in and reopen #1689 to fix afterwards

abidlabs avatar Aug 23 '22 15:08 abidlabs