mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
503 stars 131 forks source link

Automatic batch processing for certain settings #243

Open KannManMachen opened 3 months ago

KannManMachen commented 3 months ago

Hey there, is it possible to configure and run certain setups (with fixed and variable values) as batch processing?

Specifically: I would like to automatically process the (whole number) values of the "Guidance Scale" from 0 - 30 in my setup without having to manually adjust the value after each generation.

Greetings

mrhan1993 commented 3 months ago

I saw what you mentioned in the Fooocus project. But even with API, you still need to handle it manually. If I understand your requirements correctly, here is a feasible way to write a loop and pass it through params using a randomly generated float

import random
host = "http://127.0.0.1:8888"

def text2img(params: dict) -> dict:
    result = requests.post(url=f"{host}/v1/generation/text-to-image",
                           data=json.dumps(params),
                           headers={"Content-Type": "application/json"})
    return result.json()

for i in range(30):
    result =text2img({
        "prompt": "1girl sitting on the ground",
        "guidance_scale": round(random.uniform(1,30),2)
        "async_process": True
        })
    print(result)
KannManMachen commented 3 months ago

Thx for the reply @mrhan1993,

I have now come across the "function / tool" that I have been looking for all this time. It's the "Prompt Matrix / XYZ Plot grid", which you can apparently find in Automatic1111:

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/scripts/xyz_grid.py

I can use this to link various parameters (steps, CFG scale, samplers, styles, checkpoint name, etc.)
) with certain value methods (Comma Separated, Simple Range, Divided Range, Increment, Decrement).This will save me a lot of time when searching for certain setups.

So the journey continues (DALL-E 3 > Midjourney > Draw Things > Fooocus > Automatic1111 ...). Thank goodness I will still be able to control the majority with Fooocus <3

Cheers