Call fn by api_name when using Blocks.load#2593
Conversation
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2593-all-demos |
There was a problem hiding this comment.
Out of curiosity, what is the advantage of this next(generator) approach over (imo the more readable) list.index()?
There was a problem hiding this comment.
I like it cause in the case of the api_name not being there, it will return None instead of raising an exception.
Are you suggesting?
try:
fn_index = [d.get('api_name') for d in self.dependecies].index(api_name)
except ValueError:
raise (....) Happy to switch implementation!
There was a problem hiding this comment.
Yes that's what I was suggesting, but either way is fine! It probably speaks more to my personal comfort that I prefer the second over the first, I don't think there is one that's actually more pythonic
There was a problem hiding this comment.
Yea I agree both are equivalently pythonic (or non pythonic 😆 )
I personally prefer if the failure cause of a function is None (or some value like that) as opposed to raising an exception 🤷
There was a problem hiding this comment.
Suggestion -- instead of just checking the type, can we assert the correct value for a more stringent test?
There was a problem hiding this comment.
Same as above. Instead of just checking the type, can we assert the correct value for a more stringent test?
Also, I think it would be good to test with a different Space that (A) does not have a time.sleep (B) and has multiple functions that do different things to ensure that the correct function is being called
There was a problem hiding this comment.
This space has multiple functions. I'll make a copy without the sleep!
There was a problem hiding this comment.
Yup great but it would also be good if the functions were doing different things to ensure that the correct function is being called
|
Thanks for adding this @freddyaboulton! Please see a few suggestions above |
8f81077 to
e931ada
Compare
|
Thanks for the review @abidlabs ! Updated the test to use this space which has two separate functions that do separate computations |
abidlabs
left a comment
There was a problem hiding this comment.
Amazing, thanks for addressing the suggestions @freddyaboulton!
Description
Fixes #2523
Added unit tests. Can also test with some of the spaces we have in the gradio org.
Checklist:
A note about the CHANGELOG
Hello 👋 and thank you for contributing to Gradio!
All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.
Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by
[@myusername](link-to-your-github-profile)in[PR 11111](https://github.com/gradio-app/gradio/pull/11111)".If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.