fix: florence2_hires inline path — use upscale_random, not bare random
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user