-
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
Reintroduce Swagger API docs #4054
Comments
+1 as a highly desired feature note that gradio allows for defining of additional apis that don't have just gradio controls tied to them. and those were also automatically covered by swagger. if you wanted to have both docs, that would be perfectly fine - introduce new interface for gradio_client, but why remove previous interface which serves different audience? |
If your in a hurry and want to restore the api docs in the latest gradio version, you can modify it manually by running
Then change line 115 to where you want to put the swagger/redoc api docs If I remember correctly, the old default paths were (you can also just delete the doc params) |
@1lint if you're talking about modifying gradio src, that's not an option - my repo has ~35k clones in the last 2 weeks. i cannot distibute a modified gradio package. and situation with original repo is even worse - its ~0.5M clones in the last 2 weeks. and community using docs to use those repos via api or write their scripts or extensions to repos is extremely active. so whats the impact of this change? beyond massive. |
Hi @vladmandic @zolrath can you elaborate a little more on the use case for the Swagger API docs? The default Swagger API docs have some drawbacks: (1) They include lots of extraneous routes that are not useful to developers (2) They don't provide any specific information on what the payloads should be for these routes. E.g. the new API docs will tell you that |
what value? swagger docs are actually usable by anyone famillar with HTTP REST concept. not to mention that old docs they provide far more functionality in forms of actually doing validation tests and http requests. and what about when not even talking about built-in gradio routes, how about additional routes that application may define using |
You mention that the new docs are unusuable, but I'm not following why. How are you using the API docs? If you could please explain, it will help us figure out the best path forward |
if you trigger new docs, you ONLY see examples for
by documenting ONLY |
It's helpful to hear your use case. So long story short, we don't encourage the use of the HTTP API endpoints directly. They have several issues, such as timeouts for long predictions and the fact that they don't work well with the queue if queuing is enabled. We are working on releasing clients for the most popular use cases, which don't have these drawbacks. We will release a client for JS (both node and browser) in the next few days, so that this use case should be covered. |
Those are internal issues with routes.
Basically, you made from an open-model tool that Gradio was, you're going in a direction "you can do what we allow and nothing else"
One thing is to release a client, another is to force its usage. |
I totally understand what you're saying. But we want to provide a good experience to all developers, not just that know how to add additional routes. That's why we're not disabling the HTTP APIs, but just not officially documenting them -- because we can't guarantee reliable results from them. Even this is not a hard decision, we could decide to bring that back. One thing I'd like to understand -- when you say that
|
Ok. So allow such developers to enable swagger docs without modifying Gradio source code.
Neither. I just add routes to gradio's fastapi instance. import fastapi
import gradio as gr
app = gr.Blocks.launch() # this is basically fastapi instance
app.include_router(fastapi.APIRouter())
app.add_api_route("/api/v1/progress", api_progress, methods=["GET"], response_model=ProgressResponse)
class ProgressResponse(BaseModel): # inherits from base Pydantic response:
progress: float = Field(title="Progress", description="The progress with a range of 0 to 1")
def api_progress():
return {"progress": 0} and since request/response can be defined with pydantic, swagger picks it up perfectly - every field becomes automatically documented and validated. |
If you don't want to change source you can just modify the class definition at runtime. In your case its easier to do it at the fastapi level
|
money patch works - thanks! feature request is still valid - why not implement exactly that behind a flag in |
I'm astonished you're here, vladmandic, as a champion for developers representing countless peers like us. It's been tough utilizing their offering since their recent launch. I ought to propose this idea in your official repository. |
Im trying to query this API from C# and yeah, the current API docs arent very helpful to say the least.. No idea where to apply the monkeypatch. If anyone could explain how i can get the swagger UI working and HTTP requests, that would be great. |
Ok so we have a good compromise thanks to a recent PR by @akx (#4282). If you'd like to reintroduce the FastAPI docs, you can do so by passing in Just to recap the discussion above, we do not endorse the built-in FastAPI API endpoints, because: Instead, we have released Python and JS clients that allow you to use any Gradio app as an API properly. We will consider creating a more general solution. In the meantime, if you know what you're doing and you'd like to use the FastAPI docs, you can enable them using the suggestion above. |
Is your feature request related to a problem? Please describe.
Recently the
/docs
endpoint which exposed swagger API docs was removed in favor of the sidebar docs available at?view=api
.These docs simply show a list of
gradio_client
functions that can be called, limiting its usefulness to only users ofgradio_client
. There is no way to do discover how to do a simpleHTTP POST
to the API with the current docs.The previous
/docs
endpoint was generally applicable and allowed anyone to integrate a gradio project into another project, regardless of language.Describe the solution you'd like
I would love to see the Swagger API docs reintroduced at
/docs
to allow users to integrate via API more easily.The text was updated successfully, but these errors were encountered: