Mccscs2 commited on
Commit
5cccc30
·
verified ·
1 Parent(s): 9f04f38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -41,12 +41,27 @@ def generate_i2i(input_image, prompt, strength, num_inference_steps, seed, rando
41
  if randomize_seed:
42
  seed = torch.randint(0, 2**32 - 1, (1,)).item()
43
  generator = torch.Generator("cuda").manual_seed(int(seed))
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  image = pipe_i2i(
45
  prompt=prompt,
46
  image=input_image,
47
  strength=float(strength),
48
  num_inference_steps=int(num_inference_steps),
49
  generator=generator,
 
 
50
  ).images[0]
51
  return image, seed
52
 
@@ -127,7 +142,7 @@ with gr.Blocks(fill_height=True) as demo:
127
  lines=4,
128
  )
129
  with gr.Accordion("⚙️ Advanced Settings", open=False):
130
- i2i_strength = gr.Slider(0.1, 1.0, value=0.75, step=0.05, label="Strength", info="Higher = more change")
131
  i2i_steps = gr.Slider(1, 8, value=4, step=1, label="Inference Steps")
132
  with gr.Row():
133
  i2i_randomize = gr.Checkbox(label="🎲 Random Seed", value=True)
 
41
  if randomize_seed:
42
  seed = torch.randint(0, 2**32 - 1, (1,)).item()
43
  generator = torch.Generator("cuda").manual_seed(int(seed))
44
+
45
+ # Preserve original aspect ratio
46
+ orig_w, orig_h = input_image.size
47
+ # Round to nearest multiple of 64
48
+ new_w = round(orig_w / 64) * 64
49
+ new_h = round(orig_h / 64) * 64
50
+ # Cap at 1024 on longest side
51
+ scale = min(1024 / new_w, 1024 / new_h)
52
+ if scale < 1:
53
+ new_w = round(new_w * scale / 64) * 64
54
+ new_h = round(new_h * scale / 64) * 64
55
+ input_image = input_image.resize((new_w, new_h))
56
+
57
  image = pipe_i2i(
58
  prompt=prompt,
59
  image=input_image,
60
  strength=float(strength),
61
  num_inference_steps=int(num_inference_steps),
62
  generator=generator,
63
+ width=new_w,
64
+ height=new_h,
65
  ).images[0]
66
  return image, seed
67
 
 
142
  lines=4,
143
  )
144
  with gr.Accordion("⚙️ Advanced Settings", open=False):
145
+ i2i_strength = gr.Slider(0.1, 1.0, value=0.85, step=0.05, label="Strength", info="Higher = more change")
146
  i2i_steps = gr.Slider(1, 8, value=4, step=1, label="Inference Steps")
147
  with gr.Row():
148
  i2i_randomize = gr.Checkbox(label="🎲 Random Seed", value=True)