Update app.py
Browse files
app.py
CHANGED
@@ -1,84 +1,60 @@
|
|
1 |
import argparse
|
2 |
-
import random
|
3 |
from model import models
|
4 |
-
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
MAX_SEED = 2**32
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
model_name = args.model_name
|
16 |
prompt = args.prompt
|
17 |
neg_prompt = args.neg_prompt
|
18 |
width = args.width
|
19 |
height = args.height
|
20 |
steps = args.steps
|
21 |
cfg = args.cfg
|
22 |
-
seed = args.seed
|
23 |
-
|
24 |
-
positive_prefix = args.positive_prefix
|
25 |
-
positive_suffix = args.positive_suffix
|
26 |
-
negative_prefix = args.negative_prefix
|
27 |
-
negative_suffix = args.negative_suffix
|
28 |
|
29 |
-
images = infer_fn(
|
30 |
-
model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
31 |
-
positive_prefix, positive_suffix, negative_prefix, negative_suffix
|
32 |
-
)
|
33 |
-
|
34 |
-
save_gallery(images, args.output)
|
35 |
-
|
36 |
-
def random_model_image(args):
|
37 |
-
load_models(models)
|
38 |
-
|
39 |
-
model_name = random.choice(list(loaded_models.keys()))
|
40 |
-
prompt = args.prompt
|
41 |
-
neg_prompt = args.neg_prompt
|
42 |
-
width = args.width
|
43 |
-
height = args.height
|
44 |
-
steps = args.steps
|
45 |
-
cfg = args.cfg
|
46 |
-
seed = random.randint(0, MAX_SEED)
|
47 |
-
|
48 |
positive_prefix = args.positive_prefix
|
49 |
positive_suffix = args.positive_suffix
|
50 |
negative_prefix = args.negative_prefix
|
51 |
negative_suffix = args.negative_suffix
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
parser
|
62 |
-
|
63 |
-
parser.add_argument('--model_name', type=str, default=list(loaded_models.keys())[0], help='The model to use for image generation.')
|
64 |
-
parser.add_argument('--prompt', type=str, required=True, help='The prompt for image generation.')
|
65 |
-
parser.add_argument('--neg_prompt', type=str, default="", help='Negative prompt to avoid unwanted elements.')
|
66 |
-
parser.add_argument('--width', type=int, default=0, help='Image width, 0 for default.')
|
67 |
-
parser.add_argument('--height', type=int, default=0, help='Image height, 0 for default.')
|
68 |
-
parser.add_argument('--steps', type=int, default=0, help='Number of inference steps.')
|
69 |
-
parser.add_argument('--cfg', type=float, default=0, help='Guidance scale (CFG).')
|
70 |
-
parser.add_argument('--seed', type=int, default=-1, help='Random seed, -1 for random.')
|
71 |
-
parser.add_argument('--output', type=str, default="output_gallery", help='Output directory for generated images.')
|
72 |
-
parser.add_argument('--positive_prefix', nargs='*', default=[], help='Positive prefix for the prompt.')
|
73 |
-
parser.add_argument('--positive_suffix', nargs='*', default=["Common"], help='Positive suffix for the prompt.')
|
74 |
-
parser.add_argument('--negative_prefix', nargs='*', default=[], help='Negative prefix for the prompt.')
|
75 |
-
parser.add_argument('--negative_suffix', nargs='*', default=["Common"], help='Negative suffix for the prompt.')
|
76 |
|
77 |
-
parser.add_argument('--random_model', action='store_true', help='Use random model for image generation.')
|
78 |
-
|
79 |
args = parser.parse_args()
|
|
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
else:
|
84 |
-
generate_image(args)
|
|
|
1 |
import argparse
|
|
|
2 |
from model import models
|
3 |
+
from multit2i import (load_models, infer_fn, infer_rand_fn, save_gallery,
|
4 |
+
change_model, warm_model, get_model_info_md, loaded_models,
|
5 |
+
get_positive_prefix, get_positive_suffix, get_negative_prefix, get_negative_suffix,
|
6 |
+
get_recom_prompt_type, set_recom_prompt_preset, randomize_seed, translate_to_en)
|
7 |
|
8 |
+
MAX_SEED = 2**32-1
|
9 |
+
load_models(models)
|
10 |
|
11 |
+
# Define a function to handle image generation
|
12 |
+
def generate_images(args):
|
13 |
+
model_name = args.model
|
|
|
14 |
prompt = args.prompt
|
15 |
neg_prompt = args.neg_prompt
|
16 |
width = args.width
|
17 |
height = args.height
|
18 |
steps = args.steps
|
19 |
cfg = args.cfg
|
20 |
+
seed = args.seed
|
21 |
+
image_num = args.image_num
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
positive_prefix = args.positive_prefix
|
24 |
positive_suffix = args.positive_suffix
|
25 |
negative_prefix = args.negative_prefix
|
26 |
negative_suffix = args.negative_suffix
|
27 |
|
28 |
+
if seed == -1:
|
29 |
+
seed = randomize_seed()
|
30 |
+
|
31 |
+
# Infer function
|
32 |
+
for i in range(image_num):
|
33 |
+
output_image = infer_fn(model_name, prompt, neg_prompt, height, width, steps, cfg, seed,
|
34 |
+
positive_prefix, positive_suffix, negative_prefix, negative_suffix)
|
35 |
+
save_gallery(output_image, "gallery", f"output_image_{i}.png")
|
36 |
+
|
37 |
+
# CLI Arguments parsing
|
38 |
+
def main():
|
39 |
+
parser = argparse.ArgumentParser(description="Custom Image Generation CLI")
|
40 |
+
parser.add_argument("--model", type=str, required=True, help="Model name to use for generation.")
|
41 |
+
parser.add_argument("--prompt", type=str, required=True, help="Text prompt for the image.")
|
42 |
+
parser.add_argument("--neg_prompt", type=str, default="", help="Negative prompt for the image.")
|
43 |
+
parser.add_argument("--width", type=int, default=0, help="Width of the image.")
|
44 |
+
parser.add_argument("--height", type=int, default=0, help="Height of the image.")
|
45 |
+
parser.add_argument("--steps", type=int, default=0, help="Number of inference steps.")
|
46 |
+
parser.add_argument("--cfg", type=float, default=0, help="Guidance scale.")
|
47 |
+
parser.add_argument("--seed", type=int, default=-1, help="Seed for randomization.")
|
48 |
+
parser.add_argument("--image_num", type=int, default=1, help="Number of images to generate.")
|
49 |
|
50 |
+
# Prefix and Suffix options
|
51 |
+
parser.add_argument("--positive_prefix", nargs="*", default=[], help="Positive prompt prefix.")
|
52 |
+
parser.add_argument("--positive_suffix", nargs="*", default=["Common"], help="Positive prompt suffix.")
|
53 |
+
parser.add_argument("--negative_prefix", nargs="*", default=[], help="Negative prompt prefix.")
|
54 |
+
parser.add_argument("--negative_suffix", nargs="*", default=["Common"], help="Negative prompt suffix.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
|
|
|
|
56 |
args = parser.parse_args()
|
57 |
+
generate_images(args)
|
58 |
|
59 |
+
if __name__ == "__main__":
|
60 |
+
main()
|
|
|
|