Malisius / booru2prompt

An extension for stable-diffusion-webui to convert image booru posts into prompts
58 stars 8 forks source link

Extension fails to save temp.jpg on Linux #8

Open r-xnny opened 1 year ago

r-xnny commented 1 year ago

(Writing this up on mobile atm, sorry for any bad formatting)

Hi, when trying to grab tags from a Danbooru post, I get the following error in the console after the extension fails to grab the tags:

Traceback (most recent call last):
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 284, in run_
predict
    output = await app.blocks.process_api(
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 982, in proc
ess_api
    result = await self.call_function(fn_index, inputs, iterator)
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 824, in call
_function
    prediction = await anyio.to_thread.run_sync(
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run
_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 9
37, in run_sync_in_worker_thread
    return await future
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 8
67, in run
    result = context.run(func, *args)
  File "/run/media/renny/Sabrent Rocket 4/Users/renny/source/diffusing/stable-diff
usion-webui/extensions/booru2prompt/scripts/main.py", line 287, in grabtags
    urlretrieve(imageurl, edirectory +  "tempimages\\temp.jpg")
  File "/usr/lib/python3.10/urllib/request.py", line 251, in urlretrieve
    tfp = open(filename, 'wb')
OSError: [Errno 22] Invalid argument: '/run/media/renny/Sabrent Rocket 4/Users/ren
al/source/diffusing/stable-diffusion-webui/extensions/booru2prompt/tempimages\\tem
p.jpg'

I think this may be caused by the \\ in the file path for the temp image, as the urlretrieve(imageurl, edirectory + "tempimages\\temp.jpg") seems to be creating an invalid path (double backslashes being a Windows thing?). Could this be resolved by using something like os.path.join(edirectory, "tempimages", "temp.jpg") to create a platform independent path?

Davany1 commented 1 year ago

Found an easy fix.

  1. Find main.py in extensions/booru2prompt/scripts.
  2. Open it and Ctrl+F the following: tempimages\. You will find three instances of it.
  3. Simply change the two "\" to one "/" for each instance that you find. (as of today, in lines 163, 287 and 290)
  4. Restart the UI for it to reload the scripts.
  5. It should work properly now :) if you had problems with the search tab of Booru2prompt, it solves that too, just wait +-5s for the page to load.