gradio
gradio copied to clipboard
Cleaning up the way data is processed for components
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
-
preprocess_example()
being a special case ofpostprocess()
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. -
serialize()
anddeserialize()
being part ofpostprocess()
andpreprocess()
respectively.
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-1967-all-demos
Thanks guys for the review! Will go through these and fix these tonight, please let me know if you find any other failing demos
Hmm okay it looks like this breaks Interface.load
for models loaded from the Hub. Will need to dive into this more deeply tomorrow
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 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!
Thank you for reviewing so thoroughly @freddyaboulton!
Great find @freddyaboulton and thanks for the tireless reviews! Will merge it in and reopen #1689 to fix afterwards