Spaces:
Paused
Paused
SEEDING
Browse files
app.py
CHANGED
|
@@ -171,22 +171,22 @@ def remove_bkg(subject_image):
|
|
| 171 |
return subject_image
|
| 172 |
|
| 173 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 174 |
-
#
|
| 175 |
-
|
|
|
|
| 176 |
if randomize_seed:
|
| 177 |
-
|
| 178 |
-
return int(seed)
|
| 179 |
|
| 180 |
try:
|
| 181 |
# Some frontends may pass empty strings or None; coerce safely
|
| 182 |
if seed is None or (isinstance(seed, str) and seed.strip() == ""):
|
| 183 |
-
return random.randint(
|
| 184 |
seed_int = int(seed)
|
| 185 |
except Exception:
|
| 186 |
-
seed_int = random.randint(
|
| 187 |
|
| 188 |
-
# Clamp to
|
| 189 |
-
seed_int = max(
|
| 190 |
return int(seed_int)
|
| 191 |
|
| 192 |
@spaces.GPU(duration=600)
|
|
@@ -292,7 +292,7 @@ def create_image(input_image, prompt, scale, guidance_scale, num_inference_steps
|
|
| 292 |
height=height,
|
| 293 |
subject_image=input_image,
|
| 294 |
subject_scale=scale,
|
| 295 |
-
generator=torch.manual_seed(seed),
|
| 296 |
).images
|
| 297 |
else:
|
| 298 |
if style_mode == 'Makoto Shinkai style':
|
|
@@ -312,7 +312,7 @@ def create_image(input_image, prompt, scale, guidance_scale, num_inference_steps
|
|
| 312 |
height=height,
|
| 313 |
subject_image=input_image,
|
| 314 |
subject_scale=scale,
|
| 315 |
-
generator=torch.manual_seed(seed),
|
| 316 |
).images
|
| 317 |
|
| 318 |
return images
|
|
@@ -359,6 +359,9 @@ def create_multi_character_scene(char_images, prompt, scale, guidance_scale, num
|
|
| 359 |
|
| 360 |
try:
|
| 361 |
if style_mode is None:
|
|
|
|
|
|
|
|
|
|
| 362 |
scene = pipe(
|
| 363 |
prompt=char_prompt,
|
| 364 |
num_inference_steps=num_inference_steps,
|
|
@@ -367,7 +370,7 @@ def create_multi_character_scene(char_images, prompt, scale, guidance_scale, num
|
|
| 367 |
height=height,
|
| 368 |
subject_image=char_img,
|
| 369 |
subject_scale=scale * 0.7, # Smaller scale for multi-character
|
| 370 |
-
generator=torch.manual_seed(
|
| 371 |
).images[0]
|
| 372 |
else:
|
| 373 |
if style_mode == 'Makoto Shinkai style':
|
|
@@ -377,6 +380,8 @@ def create_multi_character_scene(char_images, prompt, scale, guidance_scale, num
|
|
| 377 |
lora_file_path = ghibli_style_lora_path
|
| 378 |
trigger = 'ghibli style'
|
| 379 |
|
|
|
|
|
|
|
| 380 |
scene = pipe.with_style_lora(
|
| 381 |
lora_file_path=lora_file_path,
|
| 382 |
trigger=trigger,
|
|
@@ -387,11 +392,11 @@ def create_multi_character_scene(char_images, prompt, scale, guidance_scale, num
|
|
| 387 |
height=height,
|
| 388 |
subject_image=char_img,
|
| 389 |
subject_scale=scale * 0.7,
|
| 390 |
-
generator=torch.manual_seed(
|
| 391 |
).images[0]
|
| 392 |
-
|
| 393 |
generated_scenes.append(scene)
|
| 394 |
-
|
| 395 |
# Clear memory between generations
|
| 396 |
torch.cuda.empty_cache()
|
| 397 |
|
|
|
|
| 171 |
return subject_image
|
| 172 |
|
| 173 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 174 |
+
# UI Slider bounds are +/- 1_000_000 — clamp to these so Gradio doesn't reject outputs
|
| 175 |
+
UI_MAX_SEED = 1_000_000
|
| 176 |
+
|
| 177 |
if randomize_seed:
|
| 178 |
+
return random.randint(-UI_MAX_SEED, UI_MAX_SEED)
|
|
|
|
| 179 |
|
| 180 |
try:
|
| 181 |
# Some frontends may pass empty strings or None; coerce safely
|
| 182 |
if seed is None or (isinstance(seed, str) and seed.strip() == ""):
|
| 183 |
+
return random.randint(-UI_MAX_SEED, UI_MAX_SEED)
|
| 184 |
seed_int = int(seed)
|
| 185 |
except Exception:
|
| 186 |
+
seed_int = random.randint(-UI_MAX_SEED, UI_MAX_SEED)
|
| 187 |
|
| 188 |
+
# Clamp to UI range
|
| 189 |
+
seed_int = max(-UI_MAX_SEED, min(seed_int, UI_MAX_SEED))
|
| 190 |
return int(seed_int)
|
| 191 |
|
| 192 |
@spaces.GPU(duration=600)
|
|
|
|
| 292 |
height=height,
|
| 293 |
subject_image=input_image,
|
| 294 |
subject_scale=scale,
|
| 295 |
+
generator=torch.manual_seed(int(int(seed) % 1_000_000)),
|
| 296 |
).images
|
| 297 |
else:
|
| 298 |
if style_mode == 'Makoto Shinkai style':
|
|
|
|
| 312 |
height=height,
|
| 313 |
subject_image=input_image,
|
| 314 |
subject_scale=scale,
|
| 315 |
+
generator=torch.manual_seed(int(int(seed) % 1_000_000)),
|
| 316 |
).images
|
| 317 |
|
| 318 |
return images
|
|
|
|
| 359 |
|
| 360 |
try:
|
| 361 |
if style_mode is None:
|
| 362 |
+
# Map seed to a non-negative integer within the UI range for torch
|
| 363 |
+
UI_MAX_SEED = 1_000_000
|
| 364 |
+
torch_seed = int(char_seed) % UI_MAX_SEED
|
| 365 |
scene = pipe(
|
| 366 |
prompt=char_prompt,
|
| 367 |
num_inference_steps=num_inference_steps,
|
|
|
|
| 370 |
height=height,
|
| 371 |
subject_image=char_img,
|
| 372 |
subject_scale=scale * 0.7, # Smaller scale for multi-character
|
| 373 |
+
generator=torch.manual_seed(int(torch_seed)),
|
| 374 |
).images[0]
|
| 375 |
else:
|
| 376 |
if style_mode == 'Makoto Shinkai style':
|
|
|
|
| 380 |
lora_file_path = ghibli_style_lora_path
|
| 381 |
trigger = 'ghibli style'
|
| 382 |
|
| 383 |
+
UI_MAX_SEED = 1_000_000
|
| 384 |
+
torch_seed = int(char_seed) % UI_MAX_SEED
|
| 385 |
scene = pipe.with_style_lora(
|
| 386 |
lora_file_path=lora_file_path,
|
| 387 |
trigger=trigger,
|
|
|
|
| 392 |
height=height,
|
| 393 |
subject_image=char_img,
|
| 394 |
subject_scale=scale * 0.7,
|
| 395 |
+
generator=torch.manual_seed(int(torch_seed)),
|
| 396 |
).images[0]
|
| 397 |
+
|
| 398 |
generated_scenes.append(scene)
|
| 399 |
+
|
| 400 |
# Clear memory between generations
|
| 401 |
torch.cuda.empty_cache()
|
| 402 |
|