Acly / krita-ai-diffusion

Streamlined interface for generating images with AI in Krita. Inpaint and outpaint with optional text prompt, no tweaking required.
https://www.interstice.cloud
GNU General Public License v3.0
6.96k stars 342 forks source link

Add a grace period between detecting a change and triggering generation in live preview #1412

Open modelflat opened 4 days ago

modelflat commented 4 days ago

As per discussion in #1248 this PR adds logic to delay the live preview generation upon change (without the extensions mentioned in this comment).

Acly commented 3 days ago

This is more of an absolute timer though, which doesn't refresh if there are more changes after the first change, right? I understood it as a (fairly short) period where there are no more changes instead.

It might be easier to implement that by tracking the timestamp of the last change. Since it's already a loop with a sleep it could be quite simple, something like

if self._last_input != new_input:
    current_time = time.monotonic()
    if current_time - self._last_change < grace_period:
        await self._model._generate_live(new_input)
        self._last_input = new_input
    self._last_change = time.monotonic()

I think this would make it unnecessary to pass _last_input to _generate_live and call _prepare there since that part is already handled. The just_got_here would also not be needed, since the _last_change timestamp would naturally be quite old in this case.