feature: interactive prompt

- add quiet flag
- add mask-modify-original flag
pull/28/head
Bryce 2 years ago committed by Bryce Drennan
parent 69af07ab67
commit b69b4c770e

@ -121,6 +121,7 @@ a bowl full of gold bars sitting on a table
- Prompt metadata saved into image file metadata
- Edit images by describing the part you want edited (see example above)
- Have AI generate captions for images `aimg describe <filename-or-url>`
- Interactive prompt: just run `aimg`
## How To
@ -180,7 +181,7 @@ docker run -it --gpus all -v $HOME/.cache/huggingface:/root/.cache/huggingface -
[Example Colab](https://colab.research.google.com/drive/1rOvQNs0Cmn_yU1bKWjCOHzGVDgZkaTtO?usp=sharing)
## ChangeLog
- feature: interactive prompt added. access by running `aimg`
- feature: Specify advanced text based masks using boolean logic and strength modifiers. Mask descriptions must be lowercase. Keywords uppercase.
Valid symbols: `AND`, `OR`, `NOT`, `()`, and mask strength modifier `{+0.1}` where `+` can be any of `+ - * /`
- feature: apply mask edits to original files
@ -285,7 +286,7 @@ docker run -it --gpus all -v $HOME/.cache/huggingface:/root/.cache/huggingface -
- CPU support
- ✅ img2img for plms
- img2img for kdiff functions
- image masking
- text based image masking
- https://boolean-parser.readthedocs.io/en/latest/index.html
- https://github.com/facebookresearch/detectron2
- images as actual prompts instead of just init images

@ -91,7 +91,7 @@ def imagine_image_files(
record_step_images=False,
output_file_extension="jpg",
print_caption=False,
create_modified_originals_for_masks=True,
mask_modify_original=True,
):
big_path = os.path.join(outdir, "upscaled")
masked_orig_path = os.path.join(outdir, "modified_originals")
@ -120,7 +120,7 @@ def imagine_image_files(
ddim_eta=ddim_eta,
img_callback=_record_step if record_step_images else None,
add_caption=print_caption,
create_modified_originals_for_masks=create_modified_originals_for_masks,
mask_modify_original=mask_modify_original,
):
prompt = result.prompt
basefilename = f"{base_count:06}_{prompt.seed}_{prompt.sampler_type}{prompt.steps}_PS{prompt.prompt_strength}_{prompt_normalized(prompt.prompt_text)}"
@ -151,7 +151,7 @@ def imagine(
img_callback=None,
half_mode=None,
add_caption=False,
create_modified_originals_for_masks=True,
mask_modify_original=True,
):
model = load_model()
@ -335,11 +335,7 @@ def imagine(
upscaled_img = enhance_faces(upscaled_img, fidelity=0.8)
# put the newly generated patch back into the original, full size image
if (
create_modified_originals_for_masks
and mask_image_orig
and prompt.init_image
):
if mask_modify_original and mask_image_orig and prompt.init_image:
img_to_add_back_to_original = (
upscaled_img if upscaled_img else img
)

@ -1,6 +1,7 @@
import logging.config
import click
from click_shell import shell
from imaginairy import LazyLoadingImage, generate_caption
from imaginairy.api import imagine_image_files, load_model
@ -111,12 +112,17 @@ def configure_logging(level="INFO"):
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"]),
help="What level of logs to show.",
)
@click.option(
"--quiet, -q",
is_flag=True,
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR"]),
help="Alias of `--log-level ERROR`",
)
@click.option(
"--show-work",
default=["none"],
type=click.Choice(["none", "images", "video"]),
multiple=True,
help="Make a video showing the image being created",
is_flag=True,
help="Output a debug images to `steps` folder.",
)
@click.option(
"--tile",
@ -144,6 +150,12 @@ def configure_logging(level="INFO"):
type=click.Choice(["keep", "replace"]),
help="Should we replace the masked area or keep it?",
)
@click.option(
"--mask-modify-original",
default=True,
is_flag=True,
help="After the inpainting is done",
)
@click.option(
"--caption",
default=False,
@ -174,6 +186,7 @@ def imagine_cmd(
sampler_type,
ddim_eta,
log_level,
quiet,
show_work,
tile,
mask_image,
@ -186,6 +199,8 @@ def imagine_cmd(
if ctx.invoked_subcommand is not None:
return
suppress_annoying_logs_and_warnings()
if quiet:
log_level = "ERROR"
configure_logging(log_level)
total_image_count = len(prompt_texts) * repeats
@ -233,7 +248,7 @@ def imagine_cmd(
)
@click.group("aimg")
@shell(prompt="aimg > ", intro="Starting imaginAIry...")
def aimg():
pass
@ -253,7 +268,7 @@ def describe(image_filepaths):
print(generate_caption(img.copy()))
aimg.add_command(imagine_cmd, name="generate")
aimg.add_command(imagine_cmd, name="imagine")
if __name__ == "__main__":
imagine_cmd() # noqa

@ -41,8 +41,11 @@ charset-normalizer==2.1.1
click==8.1.3
# via
# black
# click-shell
# imaginAIry (setup.py)
# typer
click-shell==2.1
# via imaginAIry (setup.py)
contourpy==1.0.5
# via matplotlib
coverage==6.4.4
@ -59,7 +62,7 @@ facexlib==0.2.5
# via
# gfpgan
# realesrgan
fairscale==0.4.9
fairscale==0.4.10
# via imaginAIry (setup.py)
filelock==3.8.0
# via
@ -95,7 +98,7 @@ google-auth-oauthlib==0.4.6
# via
# tb-nightly
# tensorboard
grpcio==1.48.1
grpcio==1.49.1
# via
# tb-nightly
# tensorboard
@ -316,7 +319,7 @@ six==1.16.0
# python-dateutil
snowballstemmer==2.2.0
# via pydocstyle
tb-nightly==2.11.0a20220921
tb-nightly==2.11.0a20220923
# via
# basicsr
# gfpgan

@ -32,6 +32,7 @@ setup(
},
install_requires=[
"click",
"click-shell",
"protobuf != 3.20.2, != 3.19.5",
"fairscale>=0.4.4", # for vendored blip
"ftfy", # for vendored clip

Loading…
Cancel
Save