Malisius / booru2prompt

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

Gelbooru support ? #2

Open yami-no-tusbas opened 1 year ago

yami-no-tusbas commented 1 year ago

I don't have danbooru account, and don't want to, is it possible to support Gelbooru ?

Error logs :

urllib.error.HTTPError: HTTP Error 422: Unprocessable Entity
https://gelbooru.com/posts.json?login=censored&api_key=censored&tags=-animated+1girl+solo+rating%3Asafe&limit=6&page=1
Traceback (most recent call last):
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 284, in run_predict
    output = await app.blocks.process_api(
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 982, in process_api
    result = await self.call_function(fn_index, inputs, iterator)
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 824, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\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 "D:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "D:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "D:\stable-diffusion-webui\extensions\booru2prompt\scripts\main.py", line 138, in searchbooru
    response = urlopen(request)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "D:\Python_3.10.6\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
https://gelbooru.com/posts.json?login=NITO333&api_key=358df02abf5a7fec138c3efac83840c93724e4973eff4ea52c395670abbba984&tags=-animated+1girl+solo+rating%3Asafe&limit=6&page=1
Traceback (most recent call last):
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 284, in run_predict
    output = await app.blocks.process_api(
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 982, in process_api
    result = await self.call_function(fn_index, inputs, iterator)
  File "D:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 824, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\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 "D:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "D:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "D:\stable-diffusion-webui\extensions\booru2prompt\scripts\main.py", line 138, in searchbooru
    response = urlopen(request)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 525, in open
    response = meth(req, response)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 634, in http_response
    response = self.parent.error(
  File "D:\Python_3.10.6\lib\urllib\request.py", line 563, in error
    return self._call_chain(*args)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "D:\Python_3.10.6\lib\urllib\request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

I tried added gelbooru, not supported, tried to fallback on danbooru, did not work I assume because I don't have credentials.

JSON Code : {"active": "Gelbooru", "negativeprompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name", "boorus": [{"name": "Danbooru", "host": "https://danbooru.donmai.us", "username": "", "apikey": ""}, {"name": "AIBooru", "host": "https://aibooru.space", "username": "", "apikey": ""}, {"name": "Gelbooru", "host": "https://gelbooru.com", "username": "censored", "apikey": "censored"}]}

Bruh, I just tested with danbooru, limited to 2 tags... not really usefull to search with, Gelbooru don't have such stupids limitations...

Here is the query for gelbooru :

https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=6&pid=0&tags=-animated%201girl%20rating%3Ageneral (credential are send on POST form) OR https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=6&pid=0&tags=-animated 1girl rating%3Ageneral&user_id=__ID__&api_key=__API_KEY__

This would return an xml-like file like danbooru.

yami-no-tusbas commented 1 year ago

here is an exemple of response from the API :

<posts limit="1" offset="0" count="246448">
<post>
<id>7956269</id>
<created_at>Thu Nov 24 08:30:35 -0600 2022</created_at>
<score>0</score>
<width>1417</width>
<height>1417</height>
<md5>803d299be841d0d4da46bda2ffca5343</md5>
<directory>80/3d</directory>
<image>803d299be841d0d4da46bda2ffca5343.png</image>
<rating>general</rating>
<source>https://itukai.tumblr.com/post/701782109617094656</source>
<change>1669300237</change>
<owner>danbooru</owner>
<creator_id>6498</creator_id>
<parent_id>0</parent_id>
<sample>1</sample>
<preview_height>250</preview_height>
<preview_width>250</preview_width>
<tags>
1boy 1girl :| ankle_socks backlighting bag bag_on_lap bag_removed bangs bench black_footwear black_pants black_socks blue_necktie blue_skirt blue_sky blue_theme blush book brown_hair closed_mouth cloud cloudy_sky collared_shirt diagonal-striped_necktie diagonal_stripes dot_nose downscaled eye_contact floating_hair hair_behind_ear highres holding holding_bag holding_book horizon itunohika legs_apart loafers looking_at_another looking_to_the_side morning necktie ocean on_bench open_book original outdoors pants park_bench parted_lips pleated_skirt reading resized road road_sign scenery school_bag school_uniform shade shadow shirt shirt_tucked_in shoes short_hair short_sleeves sidewalk sign signature sitting_on_bench skirt sky socks standing street striped striped_necktie tareme water white_shirt wide_shot wind wing_collar wooden_bench
</tags>
<title/>
<has_notes>false</has_notes>
<has_comments>false</has_comments>
<file_url>
https://img3.gelbooru.com/images/80/3d/803d299be841d0d4da46bda2ffca5343.png
</file_url>
<preview_url>
https://img3.gelbooru.com/thumbnails/80/3d/thumbnail_803d299be841d0d4da46bda2ffca5343.jpg
</preview_url>
<sample_url>
https://img3.gelbooru.com/samples/80/3d/sample_803d299be841d0d4da46bda2ffca5343.jpg
</sample_url>
<sample_height>850</sample_height>
<sample_width>850</sample_width>
<status>active</status>
<post_locked>0</post_locked>
<has_children>false</has_children>
</post>
</posts>
Malisius commented 1 year ago

The gelbooru api is unfortunately completely different than danboorus. I'll begin work on it, but I suspect it may take some time.

yami-no-tusbas commented 1 year ago

Thank you !