Spaces:
Running on Zero
Running on Zero
Make Try Another Example select random different example with auto-loaded settings
Browse files
app.py
CHANGED
|
@@ -3272,6 +3272,9 @@ if __name__ == "__main__" and not os.environ.get("QR_TESTING_MODE"):
|
|
| 3272 |
show_download_button=False,
|
| 3273 |
)
|
| 3274 |
|
|
|
|
|
|
|
|
|
|
| 3275 |
# The output image for artistic QR (initially hidden)
|
| 3276 |
artistic_output_image = gr.Image(
|
| 3277 |
label="Generated Artistic QR Code",
|
|
@@ -3404,25 +3407,55 @@ if __name__ == "__main__" and not os.environ.get("QR_TESTING_MODE"):
|
|
| 3404 |
)
|
| 3405 |
|
| 3406 |
# Event handler for "Try Another Example" button
|
| 3407 |
-
def show_examples_again():
|
| 3408 |
-
"""Show the gallery
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3409 |
return (
|
| 3410 |
gr.update(visible=False), # Hide output image
|
| 3411 |
-
"", #
|
| 3412 |
gr.update(visible=False), # Hide settings accordion
|
| 3413 |
-
gr.update(visible=True, selected_index=
|
| 3414 |
gr.update(visible=False), # Hide this button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3415 |
)
|
| 3416 |
|
| 3417 |
show_examples_btn.click(
|
| 3418 |
fn=show_examples_again,
|
| 3419 |
-
inputs=
|
| 3420 |
outputs=[
|
| 3421 |
artistic_output_image,
|
| 3422 |
artistic_error_message,
|
| 3423 |
settings_accordion_artistic,
|
| 3424 |
example_gallery,
|
| 3425 |
show_examples_btn,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3426 |
],
|
| 3427 |
)
|
| 3428 |
|
|
@@ -3445,6 +3478,7 @@ if __name__ == "__main__" and not os.environ.get("QR_TESTING_MODE"):
|
|
| 3445 |
gr.update(visible=False), # Hide output image
|
| 3446 |
"Settings loaded! Click 'Generate Artistic QR' to create your QR code", # Show in Status/Errors
|
| 3447 |
gr.update(visible=False), # Hide settings accordion
|
|
|
|
| 3448 |
)
|
| 3449 |
|
| 3450 |
# Attach the event handler
|
|
@@ -3466,6 +3500,7 @@ if __name__ == "__main__" and not os.environ.get("QR_TESTING_MODE"):
|
|
| 3466 |
artistic_output_image, # Reset visibility
|
| 3467 |
artistic_error_message, # Show status message
|
| 3468 |
settings_accordion_artistic, # Reset visibility
|
|
|
|
| 3469 |
],
|
| 3470 |
)
|
| 3471 |
|
|
|
|
| 3272 |
show_download_button=False,
|
| 3273 |
)
|
| 3274 |
|
| 3275 |
+
# State to track currently selected example index
|
| 3276 |
+
current_example_index = gr.State(value=None)
|
| 3277 |
+
|
| 3278 |
# The output image for artistic QR (initially hidden)
|
| 3279 |
artistic_output_image = gr.Image(
|
| 3280 |
label="Generated Artistic QR Code",
|
|
|
|
| 3407 |
)
|
| 3408 |
|
| 3409 |
# Event handler for "Try Another Example" button
|
| 3410 |
+
def show_examples_again(current_idx):
|
| 3411 |
+
"""Show the gallery with a random different example and load its settings"""
|
| 3412 |
+
# Pick a random index different from current
|
| 3413 |
+
available = [i for i in range(len(ARTISTIC_EXAMPLES)) if i != current_idx]
|
| 3414 |
+
new_idx = random.choice(available) if available else 0
|
| 3415 |
+
example = ARTISTIC_EXAMPLES[new_idx]
|
| 3416 |
return (
|
| 3417 |
gr.update(visible=False), # Hide output image
|
| 3418 |
+
"Settings loaded! Click 'Generate Artistic QR' to create your QR code", # Status message
|
| 3419 |
gr.update(visible=False), # Hide settings accordion
|
| 3420 |
+
gr.update(visible=True, selected_index=new_idx), # Show gallery with random selection
|
| 3421 |
gr.update(visible=False), # Hide this button
|
| 3422 |
+
# Load the example settings
|
| 3423 |
+
example["prompt"],
|
| 3424 |
+
example["text_input"],
|
| 3425 |
+
example["input_type"],
|
| 3426 |
+
example["image_size"],
|
| 3427 |
+
example["border_size"],
|
| 3428 |
+
example["error_correction"],
|
| 3429 |
+
example["module_size"],
|
| 3430 |
+
example["module_drawer"],
|
| 3431 |
+
example["use_custom_seed"],
|
| 3432 |
+
example["seed"],
|
| 3433 |
+
example["sag_blur_sigma"],
|
| 3434 |
+
new_idx, # Update current example index
|
| 3435 |
)
|
| 3436 |
|
| 3437 |
show_examples_btn.click(
|
| 3438 |
fn=show_examples_again,
|
| 3439 |
+
inputs=[current_example_index],
|
| 3440 |
outputs=[
|
| 3441 |
artistic_output_image,
|
| 3442 |
artistic_error_message,
|
| 3443 |
settings_accordion_artistic,
|
| 3444 |
example_gallery,
|
| 3445 |
show_examples_btn,
|
| 3446 |
+
# Settings outputs
|
| 3447 |
+
artistic_prompt_input,
|
| 3448 |
+
artistic_text_input,
|
| 3449 |
+
artistic_input_type,
|
| 3450 |
+
artistic_image_size,
|
| 3451 |
+
artistic_border_size,
|
| 3452 |
+
artistic_error_correction,
|
| 3453 |
+
artistic_module_size,
|
| 3454 |
+
artistic_module_drawer,
|
| 3455 |
+
artistic_use_custom_seed,
|
| 3456 |
+
artistic_seed,
|
| 3457 |
+
sag_blur_sigma,
|
| 3458 |
+
current_example_index,
|
| 3459 |
],
|
| 3460 |
)
|
| 3461 |
|
|
|
|
| 3478 |
gr.update(visible=False), # Hide output image
|
| 3479 |
"Settings loaded! Click 'Generate Artistic QR' to create your QR code", # Show in Status/Errors
|
| 3480 |
gr.update(visible=False), # Hide settings accordion
|
| 3481 |
+
evt.index, # Store the selected example index
|
| 3482 |
)
|
| 3483 |
|
| 3484 |
# Attach the event handler
|
|
|
|
| 3500 |
artistic_output_image, # Reset visibility
|
| 3501 |
artistic_error_message, # Show status message
|
| 3502 |
settings_accordion_artistic, # Reset visibility
|
| 3503 |
+
current_example_index, # Store the selected example index
|
| 3504 |
],
|
| 3505 |
)
|
| 3506 |
|