Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -337,7 +337,7 @@ logger.info("Pipeline ready.")
|
|
| 337 |
# ---------------------------------------------------------------------------
|
| 338 |
|
| 339 |
|
| 340 |
-
@spaces.GPU(duration=
|
| 341 |
def stylize(
|
| 342 |
content_image: Image.Image,
|
| 343 |
style_image: Image.Image,
|
|
@@ -358,10 +358,12 @@ def stylize(
|
|
| 358 |
if content_image is None or style_image is None:
|
| 359 |
return None
|
| 360 |
|
|
|
|
| 361 |
content_image = content_image.convert("RGB").resize((DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 362 |
style_image = style_image.convert("RGB").resize((DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 363 |
|
| 364 |
# Interpolate projector states at the requested strength
|
|
|
|
| 365 |
interp_states = interpolate_projector_states(
|
| 366 |
paths=_projector_paths,
|
| 367 |
anchor_strengths=ANCHOR_STRENGTHS,
|
|
@@ -369,10 +371,11 @@ def stylize(
|
|
| 369 |
method="bspline",
|
| 370 |
order=BSPLINE_ORDER,
|
| 371 |
spline_mode=BSPLINE_MODE,
|
| 372 |
-
device=
|
| 373 |
dtype=_dtype,
|
| 374 |
endpoint_state=_endpoint_projector_state,
|
| 375 |
)
|
|
|
|
| 376 |
_transformer.load_state_dict(interp_states, strict=False)
|
| 377 |
for _, c in _pipe.components.items():
|
| 378 |
if hasattr(c, "parameters"):
|
|
@@ -388,6 +391,7 @@ def stylize(
|
|
| 388 |
|
| 389 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 390 |
|
|
|
|
| 391 |
output = _pipe(
|
| 392 |
image=[content_image, style_image],
|
| 393 |
prompt=DEFAULT_PROMPT,
|
|
@@ -395,6 +399,7 @@ def stylize(
|
|
| 395 |
num_inference_steps=steps,
|
| 396 |
generator=generator,
|
| 397 |
)
|
|
|
|
| 398 |
return output.images[0]
|
| 399 |
|
| 400 |
|
|
|
|
| 337 |
# ---------------------------------------------------------------------------
|
| 338 |
|
| 339 |
|
| 340 |
+
@spaces.GPU(duration=180)
|
| 341 |
def stylize(
|
| 342 |
content_image: Image.Image,
|
| 343 |
style_image: Image.Image,
|
|
|
|
| 358 |
if content_image is None or style_image is None:
|
| 359 |
return None
|
| 360 |
|
| 361 |
+
logger.info("stylize called: strength=%.2f, seed=%d, steps=%d", strength, seed, steps)
|
| 362 |
content_image = content_image.convert("RGB").resize((DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 363 |
style_image = style_image.convert("RGB").resize((DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 364 |
|
| 365 |
# Interpolate projector states at the requested strength
|
| 366 |
+
logger.info("Interpolating projector states ...")
|
| 367 |
interp_states = interpolate_projector_states(
|
| 368 |
paths=_projector_paths,
|
| 369 |
anchor_strengths=ANCHOR_STRENGTHS,
|
|
|
|
| 371 |
method="bspline",
|
| 372 |
order=BSPLINE_ORDER,
|
| 373 |
spline_mode=BSPLINE_MODE,
|
| 374 |
+
device="cuda",
|
| 375 |
dtype=_dtype,
|
| 376 |
endpoint_state=_endpoint_projector_state,
|
| 377 |
)
|
| 378 |
+
logger.info("Loading interpolated states into transformer ...")
|
| 379 |
_transformer.load_state_dict(interp_states, strict=False)
|
| 380 |
for _, c in _pipe.components.items():
|
| 381 |
if hasattr(c, "parameters"):
|
|
|
|
| 391 |
|
| 392 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 393 |
|
| 394 |
+
logger.info("Running pipeline inference ...")
|
| 395 |
output = _pipe(
|
| 396 |
image=[content_image, style_image],
|
| 397 |
prompt=DEFAULT_PROMPT,
|
|
|
|
| 399 |
num_inference_steps=steps,
|
| 400 |
generator=generator,
|
| 401 |
)
|
| 402 |
+
logger.info("Pipeline done, returning image.")
|
| 403 |
return output.images[0]
|
| 404 |
|
| 405 |
|