-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Name Endpoints if api_name is None #5782
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
399ea7e
Implementation and test
freddyaboulton 2169513
add changeset
gradio-pr-bot 7abe8e8
fix lint
freddyaboulton fa2054e
merge branch 'name-endpoints-by-default' of github.com:gradio-app/gra…
freddyaboulton dccac20
Fix nits
freddyaboulton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"gradio": minor | ||
--- | ||
|
||
feat:Name Endpoints if api_name is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
from __future__ import annotations | ||
|
||
import string | ||
from functools import partial, wraps | ||
from typing import TYPE_CHECKING, Any, Callable, Literal | ||
|
||
|
@@ -168,7 +169,7 @@ def event_trigger( | |
fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. | ||
inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. | ||
outputs: List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. | ||
api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name. | ||
api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be given the name of the python function fn. If no fn is passed in, it will be given the name 'unnamed'. If set to a string, the endpoint will be exposed in the api docs with the given name. | ||
status_tracker: Deprecated and has no effect. | ||
scroll_to_output: If True, will scroll to output component on completion | ||
show_progress: If True, will show progress animation while pending | ||
|
@@ -224,6 +225,28 @@ def inner(*args, **kwargs): | |
if isinstance(show_progress, bool): | ||
show_progress = "full" if show_progress else "hidden" | ||
|
||
if api_name is None: | ||
if fn is not None: | ||
if not hasattr(fn, "__name__"): | ||
if hasattr(fn, "__class__") and hasattr( | ||
fn.__class__, "__name__" | ||
): | ||
name = fn.__class__.__name__ | ||
else: | ||
name = "unnamed" | ||
else: | ||
name = fn.__name__ | ||
api_name = "".join( | ||
[ | ||
s | ||
for s in name | ||
if s not in set(string.punctuation) - {"-", "_"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could potentially use |
||
] | ||
) | ||
else: | ||
# Don't document _js only events | ||
api_name = False | ||
|
||
dep, dep_index = block.set_event_trigger( | ||
_event_name, | ||
fn, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are a few edge cases where a user could supply a function, but it doesn't have a
__name__
(e.g. if a user supplies afunctools.partial
). We should also set the name to "unnamed" in those casesThere 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.
Yea or a class with a
__call__
method (reason why CI is failing)