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

Use data models in preprocess() #6176

Closed
wants to merge 6 commits into from
Closed

Use data models in preprocess() #6176

wants to merge 6 commits into from

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Oct 31, 2023

Picking up #6127

As discussed internally with @freddyaboulton, this uses data models in the .preprocess(), not just the .postprocess()

This PR makes the following changes:

  • Removes the serializes function: https://github.com/gradio-app/gradio/blob/v4/gradio/component_meta.py#L59 as FastAPI automatically converts Pydantic models into JSON
  • Pre-Preprocesses incoming payload from the frontend to convert to Pydantic data models before sending to .preprocess()
  • Cleans up the code as a result of the above changes, adds typing to missing places, etc.
  • Rename x to payload in preprocess() to signify that its the payload from the frontend
  • Rename y to value in postprocess() to signify its the same type as the value of the component
  • Removes docstrings from preprocess() and postprocess() because many were incorrect / outdated / rudimentary. The typing is better than the docstrings.

I think it would be better to merge this after @pngwn's #6094 PR to avoid introducing many backend conflicts to that PR.

Closes: #1798

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Oct 31, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website failed! Details
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/69680e2bf72e0b01e17a867ed58d98a602e153a0/gradio-3.50.2-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@69680e2bf72e0b01e17a867ed58d98a602e153a0#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Oct 31, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor
gradio_client minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Use data models in preprocess()

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member Author

This PR is becoming too big -- I'm going to break it up into smaller pieces and try again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standardize return types in the backend
2 participants