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
add autodocs #7030
add autodocs #7030
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/8042e9dfb3fca7020df30ef62a0ee8bd1ba5fb79/gradio-4.14.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@8042e9dfb3fca7020df30ef62a0ee8bd1ba5fb79#subdirectory=client/python" |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
I might need help with some of those type errors, I'll swap |
One or two tweaks to come but now reviewable. |
Sample markdown readme: https://gist.github.com/pngwn/d53d345e3887de357b5420581a534952 |
source = f""" | ||
import gradio as gr | ||
from app import demo as app | ||
from {name} import {",".join(filtered_keys)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these imported classes actually used? If not we can remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no, they won't be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome PR @pngwn ! I'm still going through this but wanted to comment on some things I've noticed -
- In the
space.py
thefrom app import demo as app
line will hang forever unless the app file launches the demo in aif __name__ == '__main__'
clause - In the README,
None
shows up for the badges if urls are not specified in the pyproject toml
- I can't launch the space.py for Audio docs because there's a syntax error in the file
- In the README, the types in the param table always show up as empty code blocks? Tried with lots of different components
@freddyaboulton Can you should be the generated README.md, for the empty code block case? |
I have pushed up some fixes.
|
This is great @pngwn ! Thanks for making the fixes. I can confirm they're working. I noticed the following things:
If I use 3.9 it works lol? In 3.10, the "User Function" always shows I'm seeing the same thing for the READMEs. In 3.9, the type hints get shown in the parameter table but not in 3.10. |
@freddyaboulton I think the recent update should address everything, I've also added some prettier output and warnings/ errors for certain cases.
I think CI should be green now. |
I have a type error in 3.8 (i thought 3.9 was out min version?). I'll see if i can figure that one out. |
Awesome @pngwn ! Can confirm that all of the bugs noted yesterday are now gone. Only have some questions around the content now.
|
One tiny bug is that you cannot generate docs for |
That isn't really true in a blocks world. It might be the intention but all component can be used as inputs or outputs, there is no way to restrict this so they documentation is correct and I'd think we should focus on explaining to authors that components should work as an input or an output even if they don't do much.
I'll check how I'm pulling in the docstrings. We need a docstring for the return of preprocess and the param of postprocess to generate a meaningful entry.
It's better than nothing imo, this happens because the params / returns of processors are typed but there is no docstring (or there is a bug in pulling it in). We could use the type when there is no docstring to provide some context. I'll take a look at Button. |
Ok I think there may be a bug then, annotatedimage does not have docstrings for either pre or postprocess and it has an Regarding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed these two small things!
gradio/components/paramviewer.py
Outdated
lang_type = Literal["python", "typescript"] | ||
|
||
|
||
class ParameterThree(TypedDict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would add a comment explaining that these classes are only for demonstration purposes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I'll remove these before merging.
|
||
class ParamViewer(Component): | ||
""" | ||
Displays an interactive table of parameters and their descriptions and default values width syntax highlighting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: width syntax highlighting
The reason the input/ output text was mixed up is because i got them mixed up. Annotated image docs should behave as expected now. Button thing was a bug and should be fixed. Just gonna fix that type error in 3.8 then I'll clean up the ParamViewer docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pngwn !
Only thing I noticed is that the markdown should also have the helpful explanation of the User Function section. Otherwise LGTM once CI is fixed. Thanks!
Ah yes ofc. Thanks for catching that! |
Description
This is the bulk of the work for autodocumenting custom components. To test this you will need to install
gradio_paramviewer
from pip.I will be moving this component into gradio core, so we don't need an additional dependency but I haven't quite got round to that.
I also had to remove the readme generation out while i fixed some issues but I'll add that back very shortly.
Closes #6684. Closes #6648.
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh