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

Handle special arguments when extracting parameter names for view API page #8400

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented May 28, 2024

Closes: #8399

Test with:

import gradio as gr
import time


def echo(message, request: gr.Request, num):
    return message

demo = gr.Interface(
    echo,
    ["textbox", "slider"],
    ["textbox"],
)

demo.launch()

For the case of gr.ChatInterface, we can't get the original parameter names because we construct a wrapper function over the user's defined function, so in such cases, the parameter names are generated automatically:

image

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 28, 2024

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/e686632a341e5789eb5cf482e2199c7a29dd8f2b/gradio-4.32.2-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/e686632a341e5789eb5cf482e2199c7a29dd8f2b/gradio-client-0.20.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented May 28, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Handle special arguments when extracting parameter names for view API page

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 abidlabs marked this pull request as ready for review May 28, 2024 21:35
@freddyaboulton
Copy link
Collaborator

Can we use something like functools.wraps in the chat_interface case to preserve the original signature?

Also, I was wondering why we need to construct the special args within the chat_interface function. Shouldn't that be handled by the regular request life-cycle in Blocks.

@abidlabs
Copy link
Member Author

Can we use something like functools.wraps in the chat_interface case to preserve the original signature?

I think so yes I'll take a look

Also, I was wondering why we need to construct the special args within the chat_interface function. Shouldn't that be handled by the regular request life-cycle in Blocks.

Sorry what are you referring to by this?

@freddyaboulton
Copy link
Collaborator

Sorry what are you referring to by this?

If we can use something like functools.wraps to preserve the original signature, then I don't think we need to call special_args within submit_fn because gr.Blocks will know to pass the request as an input if it sees the type hint.

@abidlabs abidlabs marked this pull request as draft June 2, 2024 19:31
@abidlabs abidlabs marked this pull request as draft June 2, 2024 19:31
@abidlabs
Copy link
Member Author

abidlabs commented Jun 3, 2024

Thanks @freddyaboulton for the suggestion. Refactored to use functools.wraps, so now we handle gr.ChatInterface with additional parameters correctly as well. For the example in the original issue, we now have:

image

@abidlabs abidlabs marked this pull request as ready for review June 3, 2024 22:33
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.

Nice. The api fn implementation for chatinterface is a lot cleaner now.

@abidlabs
Copy link
Member Author

abidlabs commented Jun 4, 2024

Indeed. Thanks @freddyaboulton for the reviews and suggestions.

@abidlabs abidlabs merged commit 33c8081 into main Jun 4, 2024
7 checks passed
@abidlabs abidlabs deleted the fix-args branch June 4, 2024 15:12
@pngwn pngwn mentioned this pull request Jun 3, 2024
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.

Additional parameters in ChatInterface have incorrect names
3 participants