integrate the Hydrus Client API #2087
Replies: 9 comments 5 replies
-
Thank you for opening this issue 😄 I'll add a few things I've been thinking about that would be nice to have re webui <-> Hydrus integrations Note: I don't think that all of these are necessarily "best implemented in the WebUI", but I'll list them here to consolidate my thoughts/before I forget Easier tag/generation parameter importingHydrus supports configuring "import folders", which allow you to specify a folder to import at specific intervals. It can also delete files after import. This makes Hydrus a good candidate for long-term storage of content generated via SD, especially at higher volumes. While you can automatically import images from folders with Hydrus, there are a few quirks that prevent the above from functioning perfectly with webui-generated content:
Currently, I have to add tags for each image manually. While this is not a problem exclusive to this scenario, it is exacerbated by how much I can easily generate with SD, and quickly gets tiresome. While there is quite a bit more that Hydrus can do, I think that being able to automatically move generated images into Hydrus—with information such as generation parameters—would make the volume of SD content I generate much easier to manage in the long run. As stated above, Hydrus can already do scheduled/automatic folder imports, but the current end result is essentially just a giant scheduled picture dump without easily visibile/associated tags, which doesn't entirely solve the long-term storage/management problem. As it stands, Regardless, thanks for your continued work on this repository, Auto! (And please pardon the brain vomit 😅) |
Beta Was this translation helpful? Give feedback.
-
Well working outside the API works well and good, but having the API will allow for much more features, like querying files for img2img use or even training data. textual diffusion training on a Hydrus query would be pretty cool. Sidecar files work but you are limited on the complexity of it all. |
Beta Was this translation helpful? Give feedback.
-
For now, I am mass renaming tag files and letting Hydrus import all the images. I was using hydrus-dd for auto tagging. Now that deepdanbooru has been integrated with this repo, I won't have to use hydrus-dd. But integration with Hydrus api would be really nice. |
Beta Was this translation helpful? Give feedback.
-
In search of a proper storage system, I've been looking into Hydrus. There isn't any news on this, is there? I want to manually tag as little as possible, and we have all this data in the chunk already, so it would be a lifesaver if there was some way to make this work. |
Beta Was this translation helpful? Give feedback.
-
After some googling, I managed to write a python script that exports the metadata of a png into a valid neighboring txt-file, import os
from PIL import Image
def main():
dirPath = "C:\\stable-diffusion-webui\\outputs\\txt2img-images" # rename this to your folder of choice
filelist = os.listdir(dirPath)
for filename in reversed(filelist):
if not(filename.endswith(".png")):
continue
if os.path.isfile(os.path.join(dirPath, filename+".txt")):
continue
im = Image.open(os.path.join(dirPath, filename))
im.load()
params = im.info['parameters'].lower()
lines = params.split("\n")
settings = getSettings(lines[len(lines)-1])
lines.remove(lines[len(lines)-1])
lineIsNegative = False
tokens = []
if len(lines) == 2:
tokens = getTokens(lines[0])
negatives = getNegatives(lines[1])
else:
for line in lines:
strippedLine = line.strip()
if strippedLine == "":
continue
if lineIsNegative:
negatives += ", " + strippedLine
continue
if strippedLine.startswith("negative prompt: "):
lineIsNegative = True
negatives = getNegatives(strippedLine)
continue
tokens += getTokens(strippedLine)
writeNewFile(dirPath, filename, negatives, tokens, settings)
def getNegatives(line):
negatives = line.replace("negative prompt: ","negative:",1)
return negatives
def getSettings(line):
setup = line.replace(": ",":") # Removes the space between the namespace and tag
settings = setup.split(",")
settings = [setting.strip().replace(" ","_") + "\n" for setting in settings]
return settings
def getTokens(line):
prompt = line.replace(":",";") # Replace : to avoid unwanted namespaces
tokens = prompt.split(",")
tokens = [token.strip().replace(" ","_") + "\n" for token in tokens]
tokens = list(filter(None, tokens))
return tokens
def writeNewFile(dirPath, filename, negatives, tokens, settings):
sidecarFile = open(os.path.join(dirPath, filename+".txt"), "w", encoding="utf-8")
sidecarFile.writelines(tokens)
sidecarFile.writelines(settings)
sidecarFile.write(negatives)
sidecarFile.close()
if __name__ == '__main__':
main() To use it, replace the string in dirPath with the path of the image folder (no recursive search - sorry, directory users) and execute it. It will only create files for PNGs that don't have a corresponding text yet, and will skip everything else. Edit: I added multiline support. Personally, I decided to not include negatives in the sidecar because I don't think it adds anything in organization, but I left it for completion's sake. If you also don't want them, just comment out the line |
Beta Was this translation helpful? Give feedback.
-
[Update for 516]Dev has added the ability to import and export txt/json sidecars via the [Update for 505]Dev has added some functionality for EXIF parsing. Going forward, the client will scan for the presence of embedded metadata in images, and will flag them as such.
Currently, you can only view the embedded metadata from the Hydrus media viewer, but as indicated in the changelog for 505:
Considering this and the previously added sidecar expansion, please check out 505/505a+! Below is OUTDATED: USE 505/505a+For those building Hydrus from source, I have thrown something together for sidecar and metadata parsing. This works with outputs (with embedded generation parameters) from both SD WebUI and NovelAI. For metadata, prompts are now added to the notes TODO:
Update for 504: metadata parsing included, sidecar SD parameter auto-parsing omitted to test new sidecar import rework from upstream, but txt files from Auto's WebUI can still be detected as sidecar files. |
Beta Was this translation helpful? Give feedback.
-
I was just looking at HydrusNetwork to solve the problem of storing and finding images as they are generated by Stable Diffusion, of which I generate hundreds a day. I'm very interested in some integration here. |
Beta Was this translation helpful? Give feedback.
-
@evanjs are you planning on opening a pull request upstream with your changes? |
Beta Was this translation helpful? Give feedback.
-
I made a better version of @horribleCodes' script that correctly parses the prompt attention and handles the prompt editing syntax. I also added compatibility with https://github.com/kohya-ss/sd-webui-additional-networks so LoRA model names/hashes are added as tags. It's available here: https://github.com/space-nuko/sd-webui-utilities/blob/master/import_to_hydrus.py It requires some extra dependencies so check the repo. I like using it as follows
|
Beta Was this translation helpful? Give feedback.
-
Integrate the Hydrus Client API!
having a folder to manage your generated files is messy and gets out of control quite quickly!
With Hydrus you can push new files to an Hydrus client and also send over any tags or prompt the user would use.
This will also work great with Deeper Danbooru!
Easier management of larger library of image generation, don't be limited by the explorer window.
Hydrus is also supported by Windows, Linux and MacOS across the board or even run from source in Python.
The API can push raw files, urls, tags and so on if you like.
Technically if integrated more fully you can also query files on the Hydrus Client to use in img2img and others.
Don't be limited by the simple limitations of filenames and folders, use tags for your seed, prompt, tags, model, settings and more!
https://github.com/hydrusnetwork/hydrus
Docs: https://hydrusnetwork.github.io/hydrus/index.html
API docs: https://hydrusnetwork.github.io/hydrus/client_api.html
https://hydrusnetwork.github.io/hydrus/developer_api.html
Side note, Hydrus can also scrape sites and boorus if you want to download a new imageset for training!
Beta Was this translation helpful? Give feedback.
All reactions