yownas / seed_travel

Small script for AUTOMATIC1111/stable-diffusion-webui to create images between two seeds
Other
310 stars 25 forks source link

Fast API support #30

Closed olegchomp closed 1 year ago

olegchomp commented 1 year ago

Will be great to add API endpoints, so scripts could be run with A1111 API requests

yownas commented 1 year ago

That would be nice. Unfortunately I don't know how to do that, it is a bit beyond my python skills. I tried to see if there were any other extensions that supported the API (that I could learn from), but couldn't find one.

olegchomp commented 1 year ago

Litte example that works. As i understand, now need to place all your code in separate file (for e.x. api.py) and set pipeline to generate on post request inside "start_travel"

from fastapi import FastAPI
import gradio as gr

import modules.script_callbacks as script_callbacks

def travel(demo: gr.Blocks, app: FastAPI):
    @app.post("/seed_travel/")
    async def start_travel(rnd_seed, seed_count):
        print(rnd_seed,seed_count)

script_callbacks.on_app_started(travel)
vladmandic commented 1 year ago

there is no clean way to add an api endpoint for an optional component.
but you already can trigger script using txt2img or img2img api endpoints, just pass optional script_name as part of api request.

olegchomp commented 1 year ago

Thank you! So another question, can you add please "output folder" parameter and save images in those. Because if i run extension with API, images doen't save anywhere. If i set "show images" in script, images come with API request, but it limits to 9-12 images, after response stuck and give no output.

vladmandic commented 1 year ago

i'll figure something out, probably next week...

olegchomp commented 1 year ago

i'll figure something out, probably next week...

thank you! i think same issue will be with prompt travel and maybe others extensions, that response with more then 1 image. I will test with batch of 10-15 images, i think it won't work too. It's mostly like a lot of data comes (base64 images), and response take a huge amount of time to load and after some time goes "500 server error"

vladmandic commented 1 year ago

this issue can be closed as my pr was merged.