AlUlkesh / stable-diffusion-webui-images-browser

an images browse for stable-diffusion-webui
629 stars 111 forks source link

Incorrect deletions happening #79

Closed Aamir3d closed 1 year ago

Aamir3d commented 1 year ago

Probably related to #78

Here's a video showing what happens.

  1. Go to the image browser.
  2. Select the image you want to delete
  3. Click the delete button ON the interface
  4. Image preview changes to another image after deletion
  5. Press DELETE KEY on keyboard
  6. Browse to other images
  7. Press DELETE KEY on keyboard to delete imag
  8. On refreshing, you see that the wrong images have been deleted

https://user-images.githubusercontent.com/122131887/224165578-e5febf2b-2fd8-46a8-afa6-b5bd6d12c2e9.mp4

AlUlkesh commented 1 year ago

A similar issue had come up for which I implemented a band-aid fix: https://github.com/AlUlkesh/stable-diffusion-webui-images-browser/issues/29

The delete logic is (I think) unnecessarily complicated. I think the best solution would be to rewrite it from scratch. I'll see if I can do that on the weekend.

AlUlkesh commented 1 year ago

@Aamir3d I'm unfortunately not able to reproduce it. I wonder if it got fixed by chance with one of the last fixes.

Can you check on your end? If you still have the issue, please note down, which image was show as an image, and which was shown as a filename. For example:

79b

Aamir3d commented 1 year ago

I'll generate a new batch of 5 files each to differentiate what's happening and share an update in a couple of hours.

Aamir3d commented 1 year ago

Check out the Fox images at the end of the video There were 6 total. I deleted 2, it should show 4 images in the UI but only displays 3

https://user-images.githubusercontent.com/122131887/224566449-e090d437-311c-4523-a0a9-c9db6859704c.mp4

On checking my file explorer folder, there are indeed 4 images image

After clicking First Page and refreshing the image browser, it shows 4 images again image

Aamir3d commented 1 year ago

Edit: Definitely happening In this updated video, you can see I clicked the delete button (1:21 in the video) on the washed out image at after a few deletions with the delete key. It didn't get deleted The actual file that was deleted was 2 thumbnails ahead

https://user-images.githubusercontent.com/122131887/224566970-6f01433d-741a-48ef-af7d-858535f725ba.mp4

Here's a list of deleted files. Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02979-4227846400-a dangerous chameleon, holding sword, silver armor, menacing background, high quality, super resolution, volumetric light, stunn.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02975-2949690161-an anthropomorphic dragon, holding sword, silver armor, menacing background, high quality, super resolution, volumetric light, s.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02966-2614036573-iridescence, a crystal fox, silver armor, menacing background, high quality, super resolution, volumetric light, stunning backgr.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02971-2503422193-iridescence, a crystal fox, silver armor, menacing background, high quality, super resolution, volumetric light, stunning backgr.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02976-2949690162-an anthropomorphic dragon, holding sword, silver armor, menacing background, high quality, super resolution, volumetric light, s.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02974-2949690160-an anthropomorphic dragon, holding sword, silver armor, menacing background, high quality, super resolution, volumetric light, s.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02962-3177354552-side pose, heroic, full body photo of a crystal chameleon, gold and blue armor, volumetric light, tree and forest background, sh.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02961-3864561927-side pose, heroic, full body photo of a crystal chameleon, gold and blue armor, volumetric light, tree and forest background, sh.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02959-3245477587-full body photo of a crystal chameleon, gold and blue armor, volumetric light, tree and forest background, shimmer, high quality.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02958-19368243-a crystal chameleon, gold and blue armor, volumetric light, tree and forest background, shimmer, high quality, super resolution,.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02960-1429322449-side pose, heroic, full body photo of a crystal chameleon, gold and blue armor, volumetric light, tree and forest background, sh.jpg Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\02955-651750557-iridescence, a crystal dragon, silver armor, menacing background, high quality, super resolution, volumetric light, stunning bac.jpg

AlUlkesh commented 1 year ago

Can you check if the image you see is ever different from the filename displayed in the lower right box?

Aamir3d commented 1 year ago

Can you check if the image you see is ever different from the filename displayed in the lower right box?

Yes, this happened with the one above. The image deleted was 2955 (last line in my previous comment) but the actual image being displayed (blurry one) was 2953 image

It's there in the video as well - it shows 2955 (crystal dragon), when it should be 2953 (crystal fox)

AlUlkesh commented 1 year ago

Thanks for the additional info. I've been trying to fix it, but so far gradio has been uncooperative. I'll continue trying some more approaches.

Aamir3d commented 1 year ago

Thanks for the additional info. I've been trying to fix it, but so far gradio has been uncooperative. I'll continue trying some more approaches.

Thank you for trying to fix this. In any case, the Image browser is a very useful tool overall, and a must for using A1111 UI. The enhancements you've been adding make it that much better.

AlUlkesh commented 1 year ago

I might have found something. I'm usually using firefox and can't replicate it. But I just thought of trying chrome - and it is happening there.

Which browser are you using?

Aamir3d commented 1 year ago

You're right, my browser is Chrome.

missionfloyd commented 1 year ago

I've noticed it seems to happen if you click delete again before it loads the info for the next image.

I think what's happening is you have the python and javascript functions running independently of each other, and they get desynced. If you put fn and _js in the same click() call, the javascript runs first, and passes its output to python.

AlUlkesh commented 1 year ago

@missionfloyd That was a really good idea.

Unfortunately, when I tried it, it seemed to get worse, it showed as if I delete something, but nothing is really deleted.

Thinking some more about it, you were on the right track, but the order is reversed. I need the javascript function to run after the python function. That's probably why it was separated like this in the original code.

I've included a generous timeout in the javascript function now and that seems to solve the issue, at least on my end.

@Aamir3d Can you check, if this also solves it for you?

missionfloyd commented 1 year ago

A workaround is run the python function and pass its output to a hidden element, then use a MutationObserver to trigger the javascript.

Gradio recently added a then() function to solve this problem.

Aamir3d commented 1 year ago

I've noticed it seems to happen if you click delete again before it loads the info for the next image.

I think what's happening is you have the python and javascript functions running independently of each other, and they get desynced. If you put fn and _js in the same click() call, the javascript runs first, and passes its output to python.

Possibly, since I was hitting the delete key fast.

@missionfloyd That was a really good idea.

Unfortunately, when I tried it, it seemed to get worse, it showed as if I delete something, but nothing is really deleted.

Thinking some more about it, you were on the right track, but the order is reversed. I need the javascript function to run after the python function. That's probably why it was separated like this in the original code.

I've included a generous timeout in the javascript function now and that seems to solve the issue, at least on my end.

@Aamir3d Can you check, if this also solves it for you?

Sure, I'll check in the next couple of hours and update this conversation.

Aamir3d commented 1 year ago

Overall the UI seems slightly slower (maybe because of the timeout?), but here's the result. I tried to delete some images (Delete key used on keyboard), I ran into a 'non deletion' error once, here's the console

Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\03557-1031507190-jim lee, 1boy, very sharp portrait,the hulk,  green hair, armor, green eyes, angry, closed mouth, crossed arms, fire background,.jpg
Deleting file O:\automatic1111\stable-diffusion-webui\outputs\txt2img-images\03556-3949759262-jim lee, 1boy, very sharp portrait,the hulk,  green hair, armor, green eyes, angry, closed mouth, crossed arms, fire background,.jpg
Traceback (most recent call last):
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 337, in run_predict
    output = await app.get_blocks().process_api(
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "O:\automatic1111\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "O:\automatic1111\stable-diffusion-webui\extensions\stable-diffusion-webui-images-browser\scripts\image_browser.py", line 286, in delete_image
    index = list(filenames).index(name)
ValueError: 'O:\\automatic1111\\stable-diffusion-webui\\outputs\\txt2img-images\\03556-3949759262-jim lee, 1boy, very sharp portrait,the hulk,  green hair, armor, green eyes, angry, closed mouth, crossed arms, fire background,.jpg' is not in list

I tried to repeat this a couple times with the delete UI button, but that seemed to work OK. I'm going to run another test with the delete key on the keyboard and see what happens.

AlUlkesh commented 1 year ago

@missionfloyd Thanks again for the pointers. I'm currently working on making a better solution than the timeout. Of course while doing this I found another issue in the old code. Gradio is such a nightmare, trying to get it to do something, that's not out-of-the-box :angry:

@Aamir3d That should also speed it up again.

Aamir3d commented 1 year ago

@missionfloyd Thanks again for the pointers. I'm currently working on making a better solution than the timeout. Of course while doing this I found another issue in the old code. Gradio is such a nightmare, trying to get it to do something, that's not out-of-the-box 😠

@Aamir3d That should also speed it up again.

Thanks! Looking forward to it.

bryanray commented 1 year ago

this happen to me too often, i stop deleting in the browser.....

AlUlkesh commented 1 year ago

@bryanray What version of the extension are you running? I thought the commit from yesterday works.

bryanray commented 1 year ago

Both, first I used the very old original version it is a messy MESS :))) then I switch to your ported version, which improved a lot of stuffs but seems some times deleting img still could be mistaken by chances, I then turn on the option something like "delete to recycle bin" so i can recover wrong deletion. I think I used the latest from you.

AlUlkesh commented 1 year ago

Trying to properly fix this has taken me far too many attempts... But I think by tomorrow I'll have a running version.

Aamir3d commented 1 year ago

Thanks for putting all the effort into this @AlUlkesh . Awaiting the next update.

AlUlkesh commented 1 year ago

See #94

@Aamir3d Thank you!