fix #8 add option to retain original workflow

This commit is contained in:
Zero ❤
2024-01-03 21:30:47 -06:00
parent 7f452c3dd4
commit 4b4c4889d9
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -123,6 +123,7 @@ watcher:
folders: folders:
- Z:\Path\To\Your\Comfy\Output\Folder - Z:\Path\To\Your\Comfy\Output\Folder
overwrite: false overwrite: false
keep_workflow: false
verbose: false verbose: false
write_suffix: __a1 write_suffix: __a1
``` ```
@@ -133,6 +134,7 @@ Modify these settings to suit your needs!
|---------|---------|-------------| |---------|---------|-------------|
| `enabled` | `true` | If the file watcher feature is enabled (or disabled). | | `enabled` | `true` | If the file watcher feature is enabled (or disabled). |
| `overwrite` | `false` | If `true`, the original file that Comfy writes will be overwritten. **NOTE:** Comfy workflow metadata is lost when converting to Civitai-compatible format, so leave this setting `false` if you want to retain copies of your workflow inside your image files! | | `overwrite` | `false` | If `true`, the original file that Comfy writes will be overwritten. **NOTE:** Comfy workflow metadata is lost when converting to Civitai-compatible format, so leave this setting `false` if you want to retain copies of your workflow inside your image files! |
| `keep_workflow` | `false` | If `true`, the original ComfyUI workflow metadata will be retained in the file, otherwise it will be removed and only the Automatic1111-compatible metadata will remain. This setting applies to both overwritten and new files. |
| `write_suffix` | `__a1` | The suffix to add to the image file when saving a copy. Has no effect if `overwrite` is `true`. | | `write_suffix` | `__a1` | The suffix to add to the image file when saving a copy. Has no effect if `overwrite` is `true`. |
| `verbose` | `false` | If `true`, prints lots more info to the console when it processes an image. | | `verbose` | `false` | If `true`, prints lots more info to the console when it processes an image. |
| `folders` | *A nonexistant sample path you must change.* | Add one or more folders that Cute Comfy should watch for new files. The files written into this folder must contain Comfy workflow metadata, so if you are using a custom saving node, ensure that you are including the metadata in the images written here. Multiple directories are supported and can be watched at the same time. | | `folders` | *A nonexistant sample path you must change.* | Add one or more folders that Cute Comfy should watch for new files. The files written into this folder must contain Comfy workflow metadata, so if you are using a custom saving node, ensure that you are including the metadata in the images written here. Multiple directories are supported and can be watched at the same time. |
+10
View File
@@ -135,6 +135,11 @@ def update_metadata(file, config_dict):
with Image.open(file) as img: with Image.open(file) as img:
metadata = img.info metadata = img.info
if 'parameters' in metadata:
if 'Seed' in metadata['parameters'] or 'Steps' in metadata['parameters']:
cuteprint(f'👀 This file already has Civitai-compatible metadata, skipping: {file}') if Verbose else None
return
if not metadata or 'workflow' not in metadata: if not metadata or 'workflow' not in metadata:
cuteprint(f'👀 This file has no metadata, can\'t do anything: {file}') if Verbose else None cuteprint(f'👀 This file has no metadata, can\'t do anything: {file}') if Verbose else None
return return
@@ -171,9 +176,14 @@ def update_metadata(file, config_dict):
Negative prompt: {prompt_negative if prompt_negative else ''} Negative prompt: {prompt_negative if prompt_negative else ''}
{f'Steps: {steps}, ' if steps else ''}{f'Sampler: {sampler}, ' if sampler else ''}{f'CFG scale: {cfg}, ' if cfg else ''}{f'Seed: {seed}, ' if seed else ''}{f'AutoConverter: Cute Comfy, '}{f'Hashes: {hashes_json}'} {f'Steps: {steps}, ' if steps else ''}{f'Sampler: {sampler}, ' if sampler else ''}{f'CFG scale: {cfg}, ' if cfg else ''}{f'Seed: {seed}, ' if seed else ''}{f'AutoConverter: Cute Comfy, '}{f'Hashes: {hashes_json}'}
''' '''
prev_metadata = metadata
metadata = PngInfo() metadata = PngInfo()
metadata.add_text("parameters", new_metadata) metadata.add_text("parameters", new_metadata)
if 'keep_workflow' in config_dict['watcher'] and config_dict['watcher']['keep_workflow']:
metadata.add_text("propmt", prev_metadata['prompt'])
metadata.add_text("workflow", prev_metadata['workflow'])
if config_dict['watcher']['overwrite']: if config_dict['watcher']['overwrite']:
img.save(file, pnginfo=metadata) img.save(file, pnginfo=metadata)
cuteprint(f'👀 💜 Updated Civitai-compatible metadata inside file: {file}') cuteprint(f'👀 💜 Updated Civitai-compatible metadata inside file: {file}')