-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow users to add a custom API route #10332
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/bce06dd34658be9bf9f5cc66ed5001d003ae473c/gradio-5.11.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@bce06dd34658be9bf9f5cc66ed5001d003ae473c#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/bce06dd34658be9bf9f5cc66ed5001d003ae473c/gradio-client-1.9.0.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/bce06dd34658be9bf9f5cc66ed5001d003ae473c/dist/lite.js""></script> |
🦄 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.
|
@@ -638,6 +638,7 @@ export function get_component( | |||
} { | |||
let example_component_map: Map<ComponentMeta["type"], LoadingComponent> = | |||
new Map(); | |||
if (type === "api") type = "state"; |
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.
instead of setting the type to "state" which could have repercussions for other code, perhaps better to have a list of non-rendered components and include both "state" and "api"
In that case, perhaps better to add explicit parameters |
Great PR @aliabid94! Generally works great. Just two suggestions:
def fn2(a: int, b: int, c):
return a + b, c[a:b]
gr.api(fn2, api_name="addition2") the gradio app fails to launch with a messy error
|
Will do in a followup that also allows editing API description |
Now users can use gr.api to add custom API routes to their apps. For example:
would add an API endpoint and API page that looks like this:
Note that it picks up type from type-hints. This endpoint will use the queue just like a normal endpoint.
It however does not yet pick up parameter and return type descriptions from the docstrings. This was because there's no consistent docstring format in python, especially for multiple return types - usually they are documented as a single return tuple which makes it hard to specify the indiviual types within the tuple. Can document in a follow up PR.
Closes: #10217