From 3f77b68a9da4299f24595401c280fc4a0ff93887 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 26 Oct 2022 18:27:35 -0400 Subject: [PATCH 1/2] fix mishandling of embedded quotes in prompt --- ldm/invoke/args.py | 50 ++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index b24620df15..26c5dc1c81 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -83,16 +83,16 @@ with metadata_from_png(): import argparse from argparse import Namespace, RawTextHelpFormatter import pydoc -import shlex import json import hashlib import os import re +import shlex import copy import base64 import functools import ldm.invoke.pngwriter -from ldm.invoke.conditioning import split_weighted_subprompts +from ldm.invoke.prompt_parser import split_weighted_subprompts SAMPLER_CHOICES = [ 'ddim', @@ -169,28 +169,24 @@ class Args(object): def parse_cmd(self,cmd_string): '''Parse a invoke>-style command string ''' - command = cmd_string.replace("'", "\\'") - try: - elements = shlex.split(command) - elements = [x.replace("\\'","'") for x in elements] - except ValueError: - import sys, traceback - print(traceback.format_exc(), file=sys.stderr) - return - switches = [''] - switches_started = False - - for element in elements: - if element[0] == '-' and not switches_started: - switches_started = True - if switches_started: - switches.append(element) + # handle the case in which the prompt is enclosed by quotes + if cmd_string.startswith('"'): + a = shlex.split(cmd_string) + prompt = a[0] + switches = shlex.join(a[1:]) + else: + # no initial quote, so get everything up to the first thing + # that looks like a switch + match = re.match('^(.+?)\s(--?[a-zA-Z].+)',cmd_string) + if match: + prompt,switches = match.groups() else: - switches[0] += element - switches[0] += ' ' - switches[0] = switches[0][: len(switches[0]) - 1] + prompt = cmd_string + switches = '' + try: - self._cmd_switches = self._cmd_parser.parse_args(switches) + self._cmd_switches = self._cmd_parser.parse_args(shlex.split(switches)) + setattr(self._cmd_switches,'prompt',prompt) return self._cmd_switches except: return None @@ -211,7 +207,9 @@ class Args(object): a = vars(self) a.update(kwargs) switches = list() - switches.append(f'"{a["prompt"]}"') + prompt = a['prompt'] + prompt.replace('"','\\"') + switches.append(prompt) switches.append(f'-s {a["steps"]}') switches.append(f'-S {a["seed"]}') switches.append(f'-W {a["width"]}') @@ -571,7 +569,11 @@ class Args(object): variation_group = parser.add_argument_group('Creating and combining variations') postprocessing_group = parser.add_argument_group('Post-processing') special_effects_group = parser.add_argument_group('Special effects') - render_group.add_argument('prompt') + render_group.add_argument( + '--prompt', + default='', + help='prompt string', + ) render_group.add_argument( '-s', '--steps', From 869d9e22c75664b0ba652c4f0947259cc836116d Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 26 Oct 2022 22:37:30 -0400 Subject: [PATCH 2/2] documentation fix --- docs/features/INPAINTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/features/INPAINTING.md b/docs/features/INPAINTING.md index 0503f1fc88..fae041a5ea 100644 --- a/docs/features/INPAINTING.md +++ b/docs/features/INPAINTING.md @@ -34,6 +34,16 @@ original unedited image and the masked (partially transparent) image: invoke> "man with cat on shoulder" -I./images/man.png -M./images/man-transparent.png ``` +If you are using Photoshop to make your transparent masks, here is a +protocol contributed by III_Communication36 (Discord name): + + Create your alpha channel for mask in photoshop, then run + image/adjust/threshold on that channel. Export as Save a copy using + superpng (3rd party free download plugin) making sure alpha channel + is selected. Then masking works as it should for the img2img + process 100%. Can feed just one image this way without needing to + feed the -M mask behind it + ## **Masking using Text** You can also create a mask using a text prompt to select the part of