stable-diffusion-webui-images-browser
stable-diffusion-webui-images-browser copied to clipboard
Error when sending to img2img
[SOLVED]
this is happening when i press "send to img2img" or "send to inpaint" from the Image Browser tab.
..but same buttons pressed in txt2img tab works fine.
:(

Same problem, but I receive bit different error after update webUI:
File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 321, in run_predict output = await app.blocks.process_api( File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1015, in process_api result = await self.call_function(fn_index, inputs, iterator, request) File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 856, in call_function prediction = await anyio.to_thread.run_sync( File "C:\ai\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 "C:\ai\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, *args) File "C:\ai\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 113, in send_image_and_dimensions img = image_from_url_text(x) File "C:\ai\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 59, in image_from_url_text filedata = base64.decodebytes(filedata.encode('utf-8')) File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python310\lib\base64.py", line 562, in decodebytes return binascii.a2b_base64(s) binascii.Error: Incorrect padding
Same problem, but I receive bit different error after update webUI:
File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 321, in run_predict output = await app.blocks.process_api( File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1015, in process_api result = await self.call_function(fn_index, inputs, iterator, request) File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 856, in call_function prediction = await anyio.to_thread.run_sync( File "C:\ai\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 "C:\ai\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "C:\ai\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, *args) File "C:\ai\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 113, in send_image_and_dimensions img = image_from_url_text(x) File "C:\ai\stable-diffusion-webui\modules\generation_parameters_copypaste.py", line 59, in image_from_url_text filedata = base64.decodebytes(filedata.encode('utf-8')) File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python310\lib\base64.py", line 562, in decodebytes return binascii.a2b_base64(s) binascii.Error: Incorrect padding
you get that red error text too in img2img tab? your error looks like the same to mine somehow, i'm not expert btw
This is error from console, in the tab I see just the same Error message in red color. But, yeah, looks like same problem.
Just an FYI this happened due to some major changes to the webui's gradio. Borked lots of extensions. Options are to roll back webui repo, wait for image-browser author to update, submit a PR with changes that fix.
Yep same here, you can always drag and drop your original image from browser until there is a fix, settings are still sent to img2img
so i guess we just have to wait for an update of this extention. Ty guys for reply
Looks like pull request #51 fixes the issue.
Did not fix here.
same. ERROR is still there
Looks like pull request #51 fixes the issue.
fixed for me
Looks like pull request #51 fixes the issue.
Seems to have worked for me as well. Don't know if it's relevant, but I overwrote the main files with the ones from #51, so I still have the .DS_Store file present in my install.
Making the change in #51 fixed the issue for me as well.
Did not fix here.
same. ERROR is still there
Pull Request #51 fixed the issue for me, but I had actually solved it myself prior to seeing this change. If #51 does not work for you, I would suggest trying my fix, which actually changes stable-diffusion-webui\modules\generation_parameters_copypaste.py. The function I edited begins at line 39 of generation_parameters_copypaste.py. I barely understand GitHub so I don't know how to link to various branches or suggest my changes.
def image_from_url_text(filedata):
if filedata == None: return None #CUSTOM CODE
if type(filedata) == list and len(filedata) > 0 and type(filedata[0]) == dict and filedata[0].get("is_file", False):
filedata = filedata[0]
if type(filedata) == dict and filedata.get("is_file", False):
filename = filedata["name"]
is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename)
assert is_in_right_dir, 'trying to open image file outside of allowed directories'
return Image.open(filename)
if type(filedata) == list:
if len(filedata) == 0:
return None
filedata = filedata[0]
# if filedata.startswith("data:image/png;base64,"): #ORIGINAL CODE
# filedata = filedata[len("data:image/png;base64,"):]
# filedata = base64.decodebytes(filedata.encode('utf-8'))
# image = Image.open(io.BytesIO(filedata))
# return image
if filedata.startswith("data:image/png;base64,"): #CUSTOM CODE
filedata = filedata[len("data:image/png;base64,"):]
# filedata = filedata+"=="
filedata = base64.decodebytes(filedata.encode('utf-8'))
else:
filedata = filedata.encode('utf-8')
image = Image.open(filedata)
return image
Just replace the current function with this version and it should work. The original code is trying to decode base64-encoded text, but it tries this whether or not the filedata has the "data:image/png;base64," string in front, which I expect to be an identifier that the decoding is necessary. My fix performs the decoding if the base64 identifier is present, or skips it if unnecessary. While I was digging around, I also realized that clicking any "send to ____" button while no image was present in the above viewer would cause an error, since the if filedata.startswith("data:image/png;base64,") check would be performed on a None type, so I added the one line if filedata == None: return None #CUSTOM CODE to circumvent the error.
@Googolplexed06 It does work well with this fix, you are the real hero!
Thank you Googolplexed06
The function I edited begins at line 39 of generation_parameters_copypaste.py
SOLVED!
i tryed remove that file and let it renew with git pull. nothing. then i made that modification at line 39 manually and voilà.. solved. thank you everyone!
seems to be broken again despite having edited the file. the fix worked until today.
[SOLVED] this is happening when i press "send to img2img" or "send to inpaint" from the Image Browser tab. ..but same buttons pressed in txt2img tab works fine. :(
![]()
Same shit, but why u made the UI look ugly?
Did not fix here.
same. ERROR is still there
Pull Request #51 fixed the issue for me, but I had actually solved it myself prior to seeing this change. If #51 does not work for you, I would suggest trying my fix, which actually changes stable-diffusion-webui\modules\generation_parameters_copypaste.py. The function I edited begins at line 39 of generation_parameters_copypaste.py. I barely understand GitHub so I don't know how to link to various branches or suggest my changes.
def image_from_url_text(filedata): if filedata == None: return None #CUSTOM CODE if type(filedata) == list and len(filedata) > 0 and type(filedata[0]) == dict and filedata[0].get("is_file", False): filedata = filedata[0] if type(filedata) == dict and filedata.get("is_file", False): filename = filedata["name"] is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename) assert is_in_right_dir, 'trying to open image file outside of allowed directories' return Image.open(filename) if type(filedata) == list: if len(filedata) == 0: return None filedata = filedata[0] # if filedata.startswith("data:image/png;base64,"): #ORIGINAL CODE # filedata = filedata[len("data:image/png;base64,"):] # filedata = base64.decodebytes(filedata.encode('utf-8')) # image = Image.open(io.BytesIO(filedata)) # return image if filedata.startswith("data:image/png;base64,"): #CUSTOM CODE filedata = filedata[len("data:image/png;base64,"):] # filedata = filedata+"==" filedata = base64.decodebytes(filedata.encode('utf-8')) else: filedata = filedata.encode('utf-8') image = Image.open(filedata) return imageJust replace the current function with this version and it should work. The original code is trying to decode base64-encoded text, but it tries this whether or not the
filedatahas the"data:image/png;base64,"string in front, which I expect to be an identifier that the decoding is necessary. My fix performs the decoding if the base64 identifier is present, or skips it if unnecessary. While I was digging around, I also realized that clicking any "send to ____" button while no image was present in the above viewer would cause an error, since theif filedata.startswith("data:image/png;base64,")check would be performed on aNonetype, so I added the one lineif filedata == None: return None #CUSTOM CODEto circumvent the error.
A simple parameter change from #51 works flawlessly. What's the point of changing the whole function?
A simple parameter change from #39 works flawlessly. What's the point of changing the whole function?
doens't work here, i just checked the line in #39 and it's already changed on my script
This whole thing is somewhat confusing. Who has tried out fix #51 and it still doesn't work? Can you please post your whole console log?
This whole thing is somewhat confusing. Who has tried out fix #51 and it still doesn't work? Can you please post your whole console log?
@4lt3r3go posted screenshot in the issue description. #51 didn't work for him.
#39 + #51 fixed it for me
A simple parameter change from #39 works flawlessly. What's the point of changing the whole function?
doens't work here, i just checked the line in #39 and it's already changed on my script
Mentioned the wrong PR, I meant #51
Well, I just had something interesting happen. Even with fix #51 I suddenly again ran into
if filedata.startswith("data:image/png;base64,"):
AttributeError: 'NoneType' object has no attribute 'startswith'
Some looking into it later, I can see this in Chrome's DevTools log:
index.0b923826.js:76 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'forEach')
at lt (index.0b923826.js:76:2728)
lt @ index.0b923826.js:76
Promise.then (async)
(anonymous) @ index.0b923826.js:76
(anonymous) @ index.0b923826.js:4
ae @ index.0b923826.js:4
f @ Number.svelte:16
(anonymous) @ index.0b923826.js:4
(anonymous) @ index.0b923826.js:4
b @ Number.svelte:19
Z.a.$$.update @ Number.svelte:32
Rl @ index.0b923826.js:4
mt @ index.0b923826.js:4
Promise.then (async)
so @ index.0b923826.js:4
zl @ index.0b923826.js:4
(anonymous) @ index.0b923826.js:4
(anonymous) @ index.0b923826.js:76
lt @ index.0b923826.js:76
Promise.then (async)
(anonymous) @ index.0b923826.js:76
(anonymous) @ index.0b923826.js:4
ae @ index.0b923826.js:4
_ @ Button.svelte:10
(anonymous) @ index.0b923826.js:4
ae @ index.0b923826.js:4
B @ Button.svelte:9
(anonymous) @ (index):1947
(index):1799 in images_history_click_image !
(index):1800 DOMTokenList(3) ['gallery-item', 'group', 'svelte-1g9btlg', value: 'gallery-item group svelte-1g9btlg']
(index):1875 tabName img2img
(index):1876 img_index -1
(index):1877 img2img_images_history_set_index
(index):1799 in images_history_click_image !
(index):1800 DOMTokenList(3) ['gallery-item', 'group', 'svelte-1g9btlg', value: 'gallery-item group svelte-1g9btlg']
(index):1875 tabName txt2img
(index):1876 img_index -1
(index):1877 txt2img_images_history_set_index
(index):1799 in images_history_click_image !
(index):1800 DOMTokenList(9) ['gallery-item', '!flex-none', '!h-9', '!w-9', 'transition-all', 'duration-75', 'scale-90', 'transform', 'svelte-1g9btlg', value: 'gallery-item !flex-none !h-9 !w-9 transition-all duration-75 scale-90 transform svelte-1g9btlg']
(index):1875 tabName txt2img
(index):1876 img_index 2
(index):1877 txt2img_images_history_set_index
(index):1799 in images_history_click_image !
So, the first time I clicked on an image I got img_index -1, which would lead to the error message about base64.
Second click on the same image, same thing.
Third click and now I get the correct img_index 2
So what is going on here? Directly before this is an error message connected to asynchronous operations. I don't know if that has anything to do with the problem, but if it does that might hint at a problem with the threading involved
Well, I just had something interesting happen. Even with fix #51 I suddenly again ran into
if filedata.startswith("data:image/png;base64,"): AttributeError: 'NoneType' object has no attribute 'startswith'
This problem was mentioned and fixed in pull request AUTOMATIC1111/stable-diffusion-webui#6541. Because of the other problems, it is still not merged.
This problem was mentioned and fixed in pull request AUTOMATIC1111/stable-diffusion-webui#6541.
Where do you see this there? I can only find a mention for if no image was present in the viewer. In my case the picture was visible.
So my current understanding is:
- #51 solves the issue for some people, some of the time
- @Googolplexed06 's solution works for most people, but Automatic makes a good point, that a function that decodes base64 should not handle something else
I hope I might now have found a new solution, that does not require a change in webui's code.
This is how we access generation_parameters_copypaste:
modules.generation_parameters_copypaste.bind_buttons(send_to_buttons, img_file_name, img_file_info)
The second parameter is currently img_file_name, which is actually a gradio textbox object with should return the filename.
#51 changes this to history_gallery, the gradio gallery object, which should return a list of images.
generation_parameters_copypaste.py's "entry" code for us is:
def send_image_and_dimensions(x):
if isinstance(x, Image.Image):
img = x
else:
img = image_from_url_text(x)
So both versions, filename and list of images, will be handled by the else, which is not really that function's purpose.
I now found that the images-browser has yet another object called hidden, which is a (hidden) gradio.image and contains the selected image and so would not have to go into the else.
So I changed the line into:
modules.generation_parameters_copypaste.bind_buttons(send_to_buttons, hidden, img_file_info)
and so far it seems to work all the time.
Could someone else please confirm this?
https://github.com/AlUlkesh/stable-diffusion-webui-images-browser/commit/d223344938b9580da20f163b4025d26cc16ddf5c
I found this thread/issue after looking into this error. I haven't dug into the history of previous fixes nor the details of what the change above is doing, but it seems to work!
Could someone else please confirm this?
#51 worked for me, this fix works too. Will you create a pull request? @AlUlkesh