Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -103,6 +103,7 @@ def generate_caption(image):
|
|
103 |
prompt = task_prompt
|
104 |
|
105 |
inputs = florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
|
|
106 |
|
107 |
generated_ids = florence_model.generate(
|
108 |
input_ids=inputs["input_ids"],
|
@@ -190,6 +191,9 @@ def tiled_flux_img2img(pipe, prompt, image, strength, steps, guidance, generator
|
|
190 |
generator=generator,
|
191 |
).images[0]
|
192 |
|
|
|
|
|
|
|
193 |
# Paste with blending if overlap
|
194 |
if overlap > 0:
|
195 |
paste_box = (x, y, x + tile_w, y + tile_h)
|
@@ -197,12 +201,14 @@ def tiled_flux_img2img(pipe, prompt, image, strength, steps, guidance, generator
|
|
197 |
# Simple linear blend on overlaps
|
198 |
mask = Image.new('L', (tile_w, tile_h), 255)
|
199 |
if x > 0:
|
200 |
-
|
|
|
201 |
for j in range(tile_h):
|
202 |
mask.putpixel((i, j), int(255 * (i / overlap)))
|
203 |
if y > 0:
|
|
|
204 |
for i in range(tile_w):
|
205 |
-
for j in range(
|
206 |
mask.putpixel((i, j), int(255 * (j / overlap)))
|
207 |
output.paste(gen_tile, paste_box, mask)
|
208 |
else:
|
|
|
103 |
prompt = task_prompt
|
104 |
|
105 |
inputs = florence_processor(text=prompt, images=image, return_tensors="pt").to(device)
|
106 |
+
inputs["pixel_values"] = inputs["pixel_values"].to(torch.float16) # Match model dtype
|
107 |
|
108 |
generated_ids = florence_model.generate(
|
109 |
input_ids=inputs["input_ids"],
|
|
|
191 |
generator=generator,
|
192 |
).images[0]
|
193 |
|
194 |
+
# Resize back to exact tile size if pipeline adjusted it
|
195 |
+
gen_tile = gen_tile.resize((tile_w, tile_h), resample=Image.LANCZOS)
|
196 |
+
|
197 |
# Paste with blending if overlap
|
198 |
if overlap > 0:
|
199 |
paste_box = (x, y, x + tile_w, y + tile_h)
|
|
|
201 |
# Simple linear blend on overlaps
|
202 |
mask = Image.new('L', (tile_w, tile_h), 255)
|
203 |
if x > 0:
|
204 |
+
blend_width = min(overlap, tile_w)
|
205 |
+
for i in range(blend_width):
|
206 |
for j in range(tile_h):
|
207 |
mask.putpixel((i, j), int(255 * (i / overlap)))
|
208 |
if y > 0:
|
209 |
+
blend_height = min(overlap, tile_h)
|
210 |
for i in range(tile_w):
|
211 |
+
for j in range(blend_height):
|
212 |
mask.putpixel((i, j), int(255 * (j / overlap)))
|
213 |
output.paste(gen_tile, paste_box, mask)
|
214 |
else:
|