Skip to content

feat: add app started callback#3982

Merged
AUTOMATIC1111 merged 2 commits into
AUTOMATIC1111:masterfrom
MaikoTan:on-started-callback
Nov 1, 2022
Merged

feat: add app started callback#3982
AUTOMATIC1111 merged 2 commits into
AUTOMATIC1111:masterfrom
MaikoTan:on-started-callback

Conversation

@MaikoTan

@MaikoTan MaikoTan commented Oct 30, 2022

Copy link
Copy Markdown
Contributor

This is useful like when you want to add a custom API route from extensions or do some post-processing for FastAPI class.

not sure if this available...
@Interpause

Copy link
Copy Markdown

If mounting custom APIs, what would the recommended path be?

I am currently thinking /sdapi/ext/<repo_name>

@MaikoTan

MaikoTan commented Nov 2, 2022

Copy link
Copy Markdown
Contributor Author

If mounting custom APIs, what would the recommended path be?

I am currently thinking /sdapi/ext/<repo_name>

I think you can use any custom paths that matches your own, as long as not to override existing ones.
For example, I have an app named dream, so I registered my custom API like this:

from fastapi import FastAPI
import gradio as gr

import modules.script_callbacks as script_callbacks

def dream(demo: gr.Blocks, app: FastAPI):
    @app.get("/dream/start")
    async def start_dream():
        # ...

    @app.get("/dream/stop")
    async def stop_dream():
        # ...

script_callbacks.on_app_started(dream)

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.

3 participants