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

Documentation-related fixes to the python client #3663

Merged
merged 29 commits into from
Mar 29, 2023
Merged

Documentation-related fixes to the python client #3663

merged 29 commits into from
Mar 29, 2023

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Mar 28, 2023

This PR:

  • Adds docstrings for the Client class and methods, clarifies that callbacks are executed sequentially
  • Adds usage information for a given API. For example, for this Space (https://abidlabs-stt-or-tts.hf.space/), getting the usage info looks like this:
client = grc.Client(space="abidlabs/stt_or_tts")
client.view_api()

which produces:

Client.predict() Usage Info
---------------------------
Named endpoints: 2
 - predict(input, api_name="predict") -> audio
    Parameters:
     - [Textbox] input: str (value)
    Returns:
     - [Audio] audio: str (filepath or URL)
 - predict(input, api_name="predict_1") -> output
    Parameters:
     - [Audio] input: str (filepath or URL)
    Returns:
     - [Textbox] output: str (value)

Unnamed endpoints: 1
 - predict(parameter_0, fn_index=2) -> input,audio
    Parameters:
     - [Dataset] parameter_0: str (value)
    Returns:
     - [Textbox] input: str (value)
     - [Audio] audio: str (filepath or URL)

You can also get the API in a machine-friendly way by simply doing client.view_api(return_info=True), so this closes #2364

In order to get this info programmatically, I expanded the set of Serializers.

Related: #3565

@gradio-pr-bot
Copy link
Collaborator

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

@abidlabs abidlabs marked this pull request as ready for review March 28, 2023 11:13
@abidlabs
Copy link
Member Author

Although still need to add tests and fix old tests, I'd appreciate a review for feedback on this documentation format and approach for getting the documentation.

cc @aliabd -- I was able to get all of the documentation entirely from the backend. I think we can remove the documentation from the frontend and use this instead.

@abidlabs abidlabs changed the title Additional fixes to the python client Documentation-related fixes to the python client Mar 28, 2023
@abidlabs
Copy link
Member Author

Synced with @freddyaboulton, I'll make some changes to this PR before opening it for reivew

@abidlabs abidlabs added the gradio_client Related to the one of the gradio client libraries label Mar 29, 2023
@abidlabs
Copy link
Member Author

@freddyaboulton after our discussion, made the following changes:

  • Added usage info about each component to the config
  • For backwards compatibility, the client looks for the usage information in the config. If not, falls back to what's provided by the serializer classes

For now, the only component that overrides the serializer info is the Slider(), to add information about its own maximum and minimum. In the future, we could extend this to other components, although imo it's better not to have too many component-specific usage info if the serializers can be sufficient.

Adding some tests and then will open this up for review

@abidlabs
Copy link
Member Author

Opening this up for review

(Note that GitHub actions is currently down, but ci.sh can be run locally)

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Solid PR @abidlabs ! Implementation looks good to me. Left some comments but nothing major. Thank you!!

client/python/gradio_client/client.py Outdated Show resolved Hide resolved
client/python/gradio_client/client.py Outdated Show resolved Hide resolved
client/python/gradio_client/client.py Outdated Show resolved Hide resolved
client/python/gradio_client/serializing.py Outdated Show resolved Hide resolved
client/python/gradio_client/client.py Outdated Show resolved Hide resolved
client/python/gradio_client/client.py Outdated Show resolved Hide resolved
@freddyaboulton
Copy link
Collaborator

This looks so slick for the stable diffusion space BTW! 🔥

image

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

@abidlabs Thanks for making the changes! This looks great. I guess we need to release to PyPi to fix the CI? Feel free to merge once CI is green - landing soonish.

@abidlabs
Copy link
Member Author

Thanks @freddyaboulton for the great suggestions! Yup still doing some more tweaks to get the machine readable part working, but I'll release to pypi once everything is working

@abidlabs
Copy link
Member Author

abidlabs commented Mar 29, 2023

All righty, did some more cleanup, now we have a machine-parsable info, everything is passing, and docs looks pretty nice imo.

Will release a new version of the client to pypi, and then merge once CI passes.

@abidlabs
Copy link
Member Author

Lots of little annoying fixes, but we should be there soon (cc @aliabd)

@abidlabs abidlabs merged commit 2a8c82d into main Mar 29, 2023
@abidlabs abidlabs deleted the pyclient2 branch March 29, 2023 22:00
@abidlabs
Copy link
Member Author

Thanks for the review @freddyaboulton, finally in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio_client Related to the one of the gradio client libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: API Introspection
3 participants