cocktailpeanut / breadboard

Stable Diffusion Browser for Windows, Mac, and Linux
https://breadboard.me
384 stars 38 forks source link

Support for A1111 ".txt" metadata....? | "undefined" when copying prompt. #14

Closed remghoost closed 1 year ago

remghoost commented 1 year ago

Hello. Super neat program. I seem to be having an issue with metadata parsing though.

I've been poking around your code with ChatGPT and I think I've noticed that you're parsing the png metadata to get the prompt and image generation parameters. I don't have that enabled on my A1111 install. Instead, I have it output the metadata as a txt file of the same name as the picture.

Here's an example of the formatting:

a picture of 6 cats doing backflips while making waffles
Negative prompt: lowres, bad anatomy, hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low normal jpeg artifacts, signature, watermark, username, blurry, out of focus
Steps: 18, Sampler: DPM++ 2M Karras, CFG scale: 12.5, Seed: 1491956809, Face restoration: CodeFormer, Size: 768x512, Hypernet: charTurner, Hypernet hash: e3b0c442, Batch size: 2, Batch pos: 0, Denoising strength: 0.78, Mask blur: 4

and the picture/file naming scheme is

1664914851512-1491956809.png
1664914851512-1491956809.txt

I'm guessing this is the script that needs to be altered.

https://github.com/cocktailpeanut/breadboard/blob/f2aa1514a341581e68ff66c16a54f0034f5e4802/crawler/parser.js#L4-L24

But I'm horrid at javascript. ChatGPT suggested adding this, but I haven't tried it yet:

convert(e, options, pictureName) {
  // code here
  // ...

  // Get the name of the text file by replacing the extension of the picture name with .txt
  let textFileName = pictureName.replace(/\.[^/.]+$/, ".txt");

  // Read the contents of the text file
  let textFileContents = fs.readFileSync(textFileName, "utf8");

  // Parse the contents of the text file as JSON
  let metadata = JSON.parse(textFileContents);

  // Use the metadata from the text file to populate the x object
  // code here
  // ...
}

I'll probably poke around at it in the next day or two. Figured I'd make an issue in case it's easy to change. I also might be entirely wrong. haha.

I'm also having an issue with large amounts of files (around 40,000 pictures) not displaying correctly, but I'll see if I can look into that too (don't hold your breath lol).