Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,11 +77,9 @@ pipe = Flux2Pipeline.from_pretrained(
|
|
| 77 |
pipe.to(device)
|
| 78 |
|
| 79 |
# Pull pre-compiled Flux2 Transformer blocks from HF hub
|
|
|
|
| 80 |
# spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
|
| 81 |
|
| 82 |
-
# 禁用编译,使用 SDPA 注意力
|
| 83 |
-
# pipe.transformer.config._attn_implementation = "sdpa"
|
| 84 |
-
# spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="sdpa")
|
| 85 |
|
| 86 |
def image_to_data_uri(img):
|
| 87 |
buffered = io.BytesIO()
|
|
@@ -128,11 +126,11 @@ def upsample_prompt_logic(prompt, image_list):
|
|
| 128 |
print(f"Upsampling failed: {e}")
|
| 129 |
return prompt
|
| 130 |
|
| 131 |
-
def update_dimensions_from_image(image_list):
|
| 132 |
"""Update width/height sliders based on uploaded image aspect ratio.
|
| 133 |
Keeps one side at 1024 and scales the other proportionally, with both sides as multiples of 8."""
|
| 134 |
if image_list is None or len(image_list) == 0:
|
| 135 |
-
return
|
| 136 |
|
| 137 |
# Get the first image to determine dimensions
|
| 138 |
img = image_list[0][0] # Gallery returns list of tuples (image, caption)
|
|
@@ -191,6 +189,9 @@ def infer(prompt, input_images=None, seed=42, randomize_seed=False, width=1024,
|
|
| 191 |
|
| 192 |
if randomize_seed:
|
| 193 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
# Prepare image list (convert None or empty gallery to None)
|
| 196 |
image_list = None
|
|
@@ -355,13 +356,6 @@ with gr.Blocks() as demo:
|
|
| 355 |
cache_mode="lazy"
|
| 356 |
)
|
| 357 |
|
| 358 |
-
# Auto-update dimensions when images are uploaded
|
| 359 |
-
input_images.upload(
|
| 360 |
-
fn=update_dimensions_from_image,
|
| 361 |
-
inputs=[input_images],
|
| 362 |
-
outputs=[width, height]
|
| 363 |
-
)
|
| 364 |
-
|
| 365 |
gr.on(
|
| 366 |
triggers=[run_button.click, prompt.submit],
|
| 367 |
fn=infer,
|
|
|
|
| 77 |
pipe.to(device)
|
| 78 |
|
| 79 |
# Pull pre-compiled Flux2 Transformer blocks from HF hub
|
| 80 |
+
# flash-attn估计库估计更新了,导致冲突了,不使用预编译的了
|
| 81 |
# spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
def image_to_data_uri(img):
|
| 85 |
buffered = io.BytesIO()
|
|
|
|
| 126 |
print(f"Upsampling failed: {e}")
|
| 127 |
return prompt
|
| 128 |
|
| 129 |
+
def update_dimensions_from_image(image_list, width, height):
|
| 130 |
"""Update width/height sliders based on uploaded image aspect ratio.
|
| 131 |
Keeps one side at 1024 and scales the other proportionally, with both sides as multiples of 8."""
|
| 132 |
if image_list is None or len(image_list) == 0:
|
| 133 |
+
return width, height # Default dimensions
|
| 134 |
|
| 135 |
# Get the first image to determine dimensions
|
| 136 |
img = image_list[0][0] # Gallery returns list of tuples (image, caption)
|
|
|
|
| 189 |
|
| 190 |
if randomize_seed:
|
| 191 |
seed = random.randint(0, MAX_SEED)
|
| 192 |
+
|
| 193 |
+
# Auto-update dimensions when images are uploaded
|
| 194 |
+
width, height = update_dimensions_from_image(input_images, width, height)
|
| 195 |
|
| 196 |
# Prepare image list (convert None or empty gallery to None)
|
| 197 |
image_list = None
|
|
|
|
| 356 |
cache_mode="lazy"
|
| 357 |
)
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
gr.on(
|
| 360 |
triggers=[run_button.click, prompt.submit],
|
| 361 |
fn=infer,
|