File size: 3,850 Bytes
cb5daed
 
5c4e8c1
232c234
1e250ff
 
 
 
5c4e8c1
232c234
5c4e8c1
1e250ff
 
 
 
 
 
 
5c4e8c1
 
 
 
 
 
 
232c234
97256ff
5c4e8c1
 
23f4f95
f70898c
23f4f95
5c4e8c1
 
23f4f95
 
 
 
f70898c
 
 
 
23f4f95
 
 
 
 
f70898c
60849d7
61ad3d2
 
5c4e8c1
 
97256ff
c348e53
97256ff
5c4e8c1
 
232c234
 
5c4e8c1
 
60849d7
61ad3d2
 
f70898c
 
 
 
 
97256ff
5c4e8c1
 
 
 
 
 
 
f70898c
9edebae
 
5c4e8c1
97256ff
5c4e8c1
c348e53
5c4e8c1
 
f70898c
5c4e8c1
 
 
232c234
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# CLI
# usage: python cli.py 'colorful calico cat artstation'
import argparse
import asyncio
from warnings import filterwarnings

from diffusers.utils import logging as diffusers_logging
from transformers import logging as transformers_logging

from lib import Config, async_call, generate

filterwarnings("ignore", category=FutureWarning, module="diffusers")
filterwarnings("ignore", category=FutureWarning, module="transformers")

# reduce verbosity but don't disable progress bars
diffusers_logging.set_verbosity_error()
transformers_logging.set_verbosity_error()


def save_images(images, filename="image.png"):
    for i, (img, _) in enumerate(images):
        name, ext = filename.rsplit(".", 1)
        img.save(f"{name}.{ext}" if len(images) == 1 else f"{name}_{i}.{ext}")


async def main():
    # fmt: off
    parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
    parser.add_argument("prompt", type=str, metavar="PROMPT")
    parser.add_argument("-n", "--negative", type=str, metavar="STR", default="")
    parser.add_argument("-e", "--embeddings", type=str, metavar="STR", default="")
    parser.add_argument("-s", "--seed", type=int, metavar="INT", default=Config.SEED)
    parser.add_argument("-i", "--images", type=int, metavar="INT", default=1)
    parser.add_argument("-f", "--filename", type=str, metavar="STR", default="image.png")
    parser.add_argument("-w", "--width", type=int, metavar="INT", default=Config.WIDTH)
    parser.add_argument("-h", "--height", type=int, metavar="INT", default=Config.HEIGHT)
    parser.add_argument("-m", "--model", type=str, metavar="STR", default=Config.MODEL)
    parser.add_argument("-d", "--deepcache", type=int, metavar="INT", default=Config.DEEPCACHE_INTERVAL)
    parser.add_argument("--lora-1", type=str, metavar="STR", default="")
    parser.add_argument("--lora-1-weight", type=float, metavar="FLOAT", default=0.0)
    parser.add_argument("--lora-2", type=str, metavar="STR", default="")
    parser.add_argument("--lora-2-weight", type=float, metavar="FLOAT", default=0.0)
    parser.add_argument("--scale", type=int, metavar="INT", choices=Config.SCALES, default=Config.SCALE)
    parser.add_argument("--style", type=str, metavar="STR", default=Config.STYLE)
    parser.add_argument("--scheduler", type=str, metavar="STR", default=Config.SCHEDULER)
    parser.add_argument("--guidance", type=float, metavar="FLOAT", default=Config.GUIDANCE_SCALE)
    parser.add_argument("--steps", type=int, metavar="INT", default=Config.INFERENCE_STEPS)
    parser.add_argument("--image-strength", type=float, metavar="FLOAT", default=Config.DENOISING_STRENGTH)
    parser.add_argument("--image", type=str, metavar="STR")
    parser.add_argument("--ip-image", type=str, metavar="STR")
    parser.add_argument("--ip-face", action="store_true")
    parser.add_argument("--taesd", action="store_true")
    parser.add_argument("--clip-skip", action="store_true")
    parser.add_argument("--karras", action="store_true")
    parser.add_argument("--freeu", action="store_true")
    # fmt: on

    args = parser.parse_args()
    images = await async_call(
        generate,
        args.prompt,
        args.negative,
        args.image,
        args.ip_image,
        args.ip_face,
        args.lora_1,
        args.lora_1_weight,
        args.lora_2,
        args.lora_2_weight,
        args.embeddings.split(",") if args.embeddings else [],
        args.style,
        args.seed,
        args.model,
        args.scheduler,
        args.width,
        args.height,
        args.guidance,
        args.steps,
        args.image_strength,
        args.deepcache,
        args.scale,
        args.images,
        args.karras,
        args.taesd,
        args.freeu,
        args.clip_skip,
    )
    save_images(images, args.filename)


if __name__ == "__main__":
    asyncio.run(main())