gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Document exposing FastAPI Application

Open omerXfaruq opened this issue 2 years ago • 3 comments

  • [X] I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
We should document that we expose FastAPI app to with demo.launch, can't see it in the docs. Also why don't we have function return values in the docs?(This can be another issue if it's missing)

Alternatively considering @pngwn comment we can

  1. don't mention it
  2. deprecate exposing the app

Though I think this unlocks a lot opportunities to the user, and makes Gradio server more flexible.

This seems unwise as it make the FastAPI api our API.

omerXfaruq avatar Jun 20 '22 15:06 omerXfaruq

I'm worried about managing which version to use, updating those dependencies, causing colossal breaking changes if we ever decide to migrate away from FastAPI. Since we are completely wrapping FastAPI we are explicitly exposing the FastAPI as our own and are on the hook for support and issues as well.

In the past we have decided to never expose response/request information in the predict functions because this complicates things for users and they should never need to interact with those objects, this feels like a similar issue. I'm not against some control + flexibility by exposing an 'app' instance but I'd prefer an abstraction over the implementation for avoid the above issues.

pngwn avatar Jun 20 '22 15:06 pngwn

IMHO there are some pros to it as @FarukOzderim mentions.

  1. I think this allows for tighter coupling when serving different endpoints for an ML API. Currently the predict endpoint in gradio fastapi is naturally more tailored towards the definitions and structure in the gradio app and as as results somesome redundant parameters end up in the predict endpoint.
  2. It will enable users to have one fastapi documentation describing the various endpoints
  3. On the server side, one can adjust no of workers and threads for the fastapi depending on their VM and parallelism requirements.

Can we have an option where users can have serverless gradio which they can then integrate into their own server/fastapi? Maybe this is for more experienced users who want to optimize and customize the server/app.

sciai-ai avatar Jun 20 '22 16:06 sciai-ai

Yeah I agree it has a lot of pros 👍

Maybe we can mention this for advanced users in the docs(and in guides), also point out that this is not a guaranteed future library support to not have deprecations in the future.

Advanced Use-case You can access the FastAPI instance with demo.app but...

omerXfaruq avatar Jun 20 '22 17:06 omerXfaruq