Skip to content

Fix gallery not being refreshed correctly#9760

Merged
AUTOMATIC1111 merged 9 commits into
AUTOMATIC1111:devfrom
Sakura-Luna:refresh
May 8, 2023
Merged

Fix gallery not being refreshed correctly#9760
AUTOMATIC1111 merged 9 commits into
AUTOMATIC1111:devfrom
Sakura-Luna:refresh

Conversation

@Sakura-Luna

Copy link
Copy Markdown
Collaborator

I'm hoping that by pushing this pr the issue of the results gallery not refreshing properly will be resolved, close #8162.

According to the test, the browser uses the cache and the results are not loaded correctly. The current fix is not perfect, if you have a more perfect way welcome to add.

@AUTOMATIC1111

AUTOMATIC1111 commented Apr 29, 2023

Copy link
Copy Markdown
Owner

save_pil_to_file function in webui makes it possible to serve a saved image without writing it to temporary directory. By appending the extra stuff to it, you're breaking that.

@Sakura-Luna

Sakura-Luna commented Apr 29, 2023

Copy link
Copy Markdown
Collaborator Author

save_pil_to_file function in webui makes it possible to serve a saved image without writing it to temporary directory. By appending the extra stuff to it, you're breaking that.

def save_pil_to_file(pil_image, dir=None):
already_saved_as = getattr(pil_image, 'already_saved_as', None)
if already_saved_as and os.path.isfile(already_saved_as):
register_tmp_file(shared.demo, already_saved_as)
file_obj = Savedfile(already_saved_as)
return file_obj
if shared.opts.temp_dir != "":
dir = shared.opts.temp_dir
use_metadata = False
metadata = PngImagePlugin.PngInfo()
for key, value in pil_image.info.items():
if isinstance(key, str) and isinstance(value, str):
metadata.add_text(key, value)
use_metadata = True
file_obj = tempfile.NamedTemporaryFile(delete=False, suffix=".png", dir=dir)
pil_image.save(file_obj, pnginfo=(metadata if use_metadata else None))
return file_obj

You mean this? I noticed that register_tmp_file registers the saved file to gradio, which is exactly the location to be modified, and the path mounted by gradio will cause the gallery not to refresh after the file with the same name is saved.

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

The solution I had in mind was to add the question mark with time just before the image is served, not to the already_saved_as field, which would remain as a proper filename.

669b518

@Sakura-Luna

Sakura-Luna commented May 8, 2023

Copy link
Copy Markdown
Collaborator Author

@AUTOMATIC1111 The Replace preview image functionality is also broken and looks like it needs a similar fix a3cdf9a.
image

@Sakura-Luna

Copy link
Copy Markdown
Collaborator Author

I think unifying the address of gradio and file_obj can reduce some complexity to avoid confusion? The premise is that modifying gradio at the same time will not introduce more incompatibilities.
image

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

It also breaks "Save" button - either implementation. I reverted the change because this for sure will also break a bunch of extensions. There should be a better solution than this.

@Sakura-Luna

Copy link
Copy Markdown
Collaborator Author

It also breaks "Save" button - either implementation. I reverted the change because this for sure will also break a bunch of extensions.

You mean the Save button under the gallery? It seems to work fine on my branch.
image

There should be a better solution than this.

In the final analysis, it is a problem caused by the browser's use of cache. I tried to insert no-cache but it didn't work. This is the only effective solution I found, and it is not difficult to be compatible. You only need to remove the characters at the end. If it What is broken can also be easily fixed, I don't know what extensions are affected by it.

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

I put it to you that this is not caused by browser cache:

  1. change settings to always save image as a.png
  2. make an image
  3. make another image, observe that you get the same output as first time
  4. open the image in a new tab, observe that a different image from first time appears
  5. go back to txt2img and generate another image

The expectation after 5 if the browser cache is at fault is that the image will change to the the image produced in step 3, since it is what is in the cache currently. Reality is you'll still see the initial image from step 2.

@AUTOMATIC1111

Copy link
Copy Markdown
Owner

I guess it is cache, the browser does not even make a request.

@Sakura-Luna

Copy link
Copy Markdown
Collaborator Author

When I generate an image and then delete it to generate another, I can observe no change here.
image

But if you open in a new tab, it will be new, and devtools will still not change at this time.

@AUTOMATIC1111 AUTOMATIC1111 changed the base branch from master to dev May 8, 2023 12:05
@AUTOMATIC1111 AUTOMATIC1111 merged commit 879ed54 into AUTOMATIC1111:dev May 8, 2023
@Sakura-Luna Sakura-Luna deleted the refresh branch May 8, 2023 12:25
@wzgrx

wzgrx commented May 9, 2023

Copy link
Copy Markdown
Contributor

The preview function seems to be broken, the preview image is cracked

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

Successfully merging this pull request may close these issues.

[Bug]: Web shows the wrong result

3 participants