Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After interrogation is started, can't abort - Batch interrogate #76

Open
scofano opened this issue Sep 28, 2023 · 7 comments
Open

After interrogation is started, can't abort - Batch interrogate #76

scofano opened this issue Sep 28, 2023 · 7 comments

Comments

@scofano
Copy link

scofano commented Sep 28, 2023

After it is started, can't abort Batch interrogate. I started a folder with 100 images and then realized it was the wrong folder, I had to close SD because I didn't find how to stop the process.

@picobyte
Copy link
Owner

picobyte commented Sep 28, 2023

well yeah, that happens.

@picobyte picobyte closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@picobyte
Copy link
Owner

I guess the interrogate button could change in Cancel a bit similar to txt2img or img2img.

@scofano
Copy link
Author

scofano commented Sep 29, 2023

It would be great.

@picobyte
Copy link
Owner

picobyte commented Sep 29, 2023

The button to change into Cancel after a press. The press of this button should function according a toggled state (e.g. a static interrogator bool)
As you can read here, under behavior by usinng the label button as output it is possible to change the button label (temporarily)

The loop to break
Also make sure to reinstate the interrogate button after interrogation is done, also after errors.

@picobyte picobyte reopened this Sep 29, 2023
@WSH032
Copy link

WSH032 commented Sep 30, 2023

I think maybe it would be easier to implement and maintain with two buttons.

Maybe like this, two buttons, Interrogate and Cancel
When Interrogate is pressed, it hides itself and displays Cancel.
When Cancel is pressed, do the similar thing.

refer to https://www.gradio.app/docs/button#initialization, we can use visible or interactive to implement


This is demo:

import time
from threading import Event

import gradio as gr


############################################

cancel_event = Event()


SHOW_INTERROGATE = [
    gr.update(visible = True),
    gr.update(visible = False),
]
SHOW_CANCEL = SHOW_INTERROGATE[::-1]


############################################

def fake_interrogate():

    cancel_event.clear()  # reset cancel event

    yield SHOW_CANCEL

    # fake interrogate
    for i in range(10):
        if cancel_event.isSet():  # check if cancel event is set
            print("canceled")
            break
        time.sleep(1)
        print(i)
    yield SHOW_INTERROGATE


def fake_cancel():
    cancel_event.set()  # set cancel event to stop the interrogation
    return SHOW_INTERROGATE


############################################

with gr.Blocks() as demo:

    with gr.Row():
        interrogate = gr.Button(value="interrogate")
        cancel = gr.Button(value="cancel", visible=False)

    interrogate.click(
        fn = fake_interrogate,
        outputs=[interrogate, cancel],
    )

    cancel.click(
        fn = fake_cancel,
        outputs=[interrogate, cancel],
    )

# queue is required to yield, and `concurrency_count` must be > 1 (in A1111 seems 64)
demo.queue(concurrency_count=2).launch(debug=True)

@picobyte
Copy link
Owner

Thanks for your input, you are right, It is difficult to return and change the label before interrogation. Maybe it can be done by queuing th interrogation, then returning, but then the double button may be easier.

@RoelKluin
Copy link

It might also be possible to use a state variable, let the button just handle the label change and change the state of the state variable. Then the state variable, on change should trigger either the batch interrogation or the cancel action, dependent on its (inverted) state. Another approach could be to use the elem_id and change the button label in javascript, rather than relying on gradio.

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

No branches or pull requests

4 participants