15
15
16
16
17
17
def make_demo (pipeline , generator_cls , image_to_tensor ):
18
- def infer (input_image , prompt , negative_prompt , seed , strength , randomize_seed , num_inference_steps , progress = gr .Progress (track_tqdm = True )):
18
+ def infer (input_image , prompt , negative_prompt , seed , strength , randomize_seed , num_inference_steps , use_custom_size , height , width , progress = gr .Progress (track_tqdm = True )):
19
19
if randomize_seed :
20
20
seed = np .random .randint (0 , MAX_SEED )
21
21
@@ -25,9 +25,16 @@ def infer(input_image, prompt, negative_prompt, seed, strength, randomize_seed,
25
25
pbar = tqdm (total = math .ceil ((num_inference_steps + 1 ) * strength ))
26
26
27
27
def callback (step , num_steps , latent ):
28
+ if pbar .total != num_steps :
29
+ pbar .reset (total = num_steps )
28
30
pbar .update (1 )
29
31
sys .stdout .flush ()
30
32
return False
33
+ additional_args = {}
34
+
35
+ if use_custom_size :
36
+ additional_args = {"height" : height , "width" : width }
37
+
31
38
32
39
image_tensor = pipeline .generate (
33
40
prompt ,
@@ -37,6 +44,7 @@ def callback(step, num_steps, latent):
37
44
generator = generator ,
38
45
strength = strength ,
39
46
callback = callback ,
47
+ ** additional_args
40
48
)
41
49
42
50
return image_tensor .data [0 ], seed
@@ -93,12 +101,14 @@ def callback(step, num_steps, latent):
93
101
step = 1 ,
94
102
value = 20 ,
95
103
)
96
-
104
+ use_custom_size = gr .Checkbox (label = "Use custom height and width" , value = False )
105
+ width = gr .Slider (label = "Width" , minimum = 256 , maximum = MAX_IMAGE_SIZE , step = 64 , value = 512 )
106
+ height = gr .Slider (label = "Height" , minimum = 256 , maximum = MAX_IMAGE_SIZE , step = 64 , value = 512 )
97
107
gr .Examples (examples = examples , inputs = [input_image , prompt ])
98
108
gr .on (
99
109
triggers = [run_button .click , prompt .submit , negative_prompt .submit ],
100
110
fn = infer ,
101
- inputs = [input_image , prompt , negative_prompt , seed , strength , randomize_seed , num_inference_steps ],
111
+ inputs = [input_image , prompt , negative_prompt , seed , strength , randomize_seed , num_inference_steps , use_custom_size , height , width ],
102
112
outputs = [result , seed ],
103
113
)
104
114
0 commit comments