From 90dcdc955158dd033cd332f11ec6572dced90a2f Mon Sep 17 00:00:00 2001 From: Jason Hoku Date: Mon, 18 May 2026 08:43:46 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20florence2=5Fhires=20inline=20path=20?= =?UTF-8?q?=E2=80=94=20use=20upscale=5Frandom,=20not=20bare=20random?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UnboundLocalError at runtime: 'cannot access local variable random where it is not associated with a value'. Cause: Python scopes 'random' as a local of the entire _run_jobs function (it's imported as a bare name later in the function at L2471 etc), so any earlier reference triggers UnboundLocalError. The inline upscale loop imports 'import random as upscale_random' at L1797 specifically to avoid this — my Florence2 code (and seedvr2's at L2035) used bare 'random.randint' which shadowed the local. Switched both my sites + the pre-existing seedvr2 site to upscale_random. Tests still 96/96 green. --- generation_orchestrator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generation_orchestrator.py b/generation_orchestrator.py index be6cc64..7b5b830 100644 --- a/generation_orchestrator.py +++ b/generation_orchestrator.py @@ -1939,7 +1939,7 @@ def run_generation_loop( # it lives at ~L2324, AFTER the upscale loop. Use # create_image_metadata directly (matches the normal # hires/model upscale path at L2184). - sentinel_id = int(time.time() * 100000) + random.randint(0, 1000) + sentinel_id = int(time.time() * 100000) + upscale_random.randint(0, 1000) sentinel_meta = create_image_metadata( conf, pipe_w, pipe_h, float(step_result.get("duration", 0)), @@ -1967,7 +1967,7 @@ def run_generation_loop( # `meta` is not yet assigned at this point in the function; # build the entry via create_image_metadata directly (matches # the normal hires/model upscale path at L2184). - upscale_id = int(time.time() * 100000) + random.randint(0, 1000) + upscale_id = int(time.time() * 100000) + upscale_random.randint(0, 1000) upscaled_filename = f"img_{upscale_id}.webp" filepath = os.path.join(paths["images"], upscaled_filename) step_result["image_pil"].save(filepath, format="WEBP", quality=95) @@ -2032,7 +2032,7 @@ def run_generation_loop( is_final_output = is_last_step if is_final_output: # Save the upscaled image and update manifest - upscale_id = int(time.time() * 100000) + random.randint(0, 1000) + upscale_id = int(time.time() * 100000) + upscale_random.randint(0, 1000) upscaled_filename = f"img_{upscale_id}.webp" filepath = os.path.join(paths["images"], upscaled_filename) result_pil.save(filepath, quality=80)