Spaces:
Running on Zero
Running on Zero
Update PixelSmile demo
Browse files- .gitignore +1 -0
- README.md +1 -1
- gradio_app/edit.py +12 -1
.gitignore
CHANGED
|
@@ -2,3 +2,4 @@ weights/*
|
|
| 2 |
!weights/.gitkeep
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
|
|
|
|
|
| 2 |
!weights/.gitkeep
|
| 3 |
__pycache__/
|
| 4 |
*.pyc
|
| 5 |
+
*.log
|
README.md
CHANGED
|
@@ -8,7 +8,7 @@ sdk_version: 6.10.0
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: PixelSmile Demo [
|
| 12 |
---
|
| 13 |
|
| 14 |
We are actively working to bring this demo online soon.
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: PixelSmile Demo [🔨Developing]
|
| 12 |
---
|
| 13 |
|
| 14 |
We are actively working to bring this demo online soon.
|
gradio_app/edit.py
CHANGED
|
@@ -51,6 +51,7 @@ def run_edit(
|
|
| 51 |
seed: int,
|
| 52 |
weight_version: str,
|
| 53 |
num_inference_steps: int,
|
|
|
|
| 54 |
) -> Image.Image:
|
| 55 |
import torch
|
| 56 |
|
|
@@ -64,12 +65,18 @@ def run_edit(
|
|
| 64 |
num_inference_steps,
|
| 65 |
)
|
| 66 |
subject = get_subject_name(data_type)
|
|
|
|
|
|
|
| 67 |
pipe = load_lora(weight_version)
|
|
|
|
|
|
|
| 68 |
input_image = prepare_input_image(image)
|
| 69 |
logger.info("Input image prepared at size: %s", input_image.size)
|
| 70 |
edit_condition = build_edit_condition(subject, expression, float(scale))
|
| 71 |
logger.info("Edit condition: %s", edit_condition)
|
| 72 |
|
|
|
|
|
|
|
| 73 |
prompt_embeds, prompt_embeds_mask = compute_text_embeddings(
|
| 74 |
method=DEFAULT_METHOD,
|
| 75 |
pipeline=pipe,
|
|
@@ -80,10 +87,12 @@ def run_edit(
|
|
| 80 |
logger.info(
|
| 81 |
"Prompt embeds ready: embeds_shape=%s, mask_shape=%s",
|
| 82 |
tuple(prompt_embeds.shape),
|
| 83 |
-
tuple(prompt_embeds_mask.shape),
|
| 84 |
)
|
| 85 |
|
| 86 |
generator = torch.Generator(device=pipe.device).manual_seed(int(seed))
|
|
|
|
|
|
|
| 87 |
logger.info("Starting pipeline inference with %s steps", num_inference_steps)
|
| 88 |
with torch.no_grad():
|
| 89 |
output = pipe(
|
|
@@ -96,4 +105,6 @@ def run_edit(
|
|
| 96 |
generator=generator,
|
| 97 |
)
|
| 98 |
logger.info("Pipeline inference finished")
|
|
|
|
|
|
|
| 99 |
return output.images[0]
|
|
|
|
| 51 |
seed: int,
|
| 52 |
weight_version: str,
|
| 53 |
num_inference_steps: int,
|
| 54 |
+
progress=None,
|
| 55 |
) -> Image.Image:
|
| 56 |
import torch
|
| 57 |
|
|
|
|
| 65 |
num_inference_steps,
|
| 66 |
)
|
| 67 |
subject = get_subject_name(data_type)
|
| 68 |
+
if progress is not None:
|
| 69 |
+
progress(0.15, desc="Loading PixelSmile weights...")
|
| 70 |
pipe = load_lora(weight_version)
|
| 71 |
+
if progress is not None:
|
| 72 |
+
progress(0.35, desc="Preparing input image...")
|
| 73 |
input_image = prepare_input_image(image)
|
| 74 |
logger.info("Input image prepared at size: %s", input_image.size)
|
| 75 |
edit_condition = build_edit_condition(subject, expression, float(scale))
|
| 76 |
logger.info("Edit condition: %s", edit_condition)
|
| 77 |
|
| 78 |
+
if progress is not None:
|
| 79 |
+
progress(0.5, desc="Encoding edit condition...")
|
| 80 |
prompt_embeds, prompt_embeds_mask = compute_text_embeddings(
|
| 81 |
method=DEFAULT_METHOD,
|
| 82 |
pipeline=pipe,
|
|
|
|
| 87 |
logger.info(
|
| 88 |
"Prompt embeds ready: embeds_shape=%s, mask_shape=%s",
|
| 89 |
tuple(prompt_embeds.shape),
|
| 90 |
+
None if prompt_embeds_mask is None else tuple(prompt_embeds_mask.shape),
|
| 91 |
)
|
| 92 |
|
| 93 |
generator = torch.Generator(device=pipe.device).manual_seed(int(seed))
|
| 94 |
+
if progress is not None:
|
| 95 |
+
progress(0.7, desc=f"Running inference ({int(num_inference_steps)} steps)...")
|
| 96 |
logger.info("Starting pipeline inference with %s steps", num_inference_steps)
|
| 97 |
with torch.no_grad():
|
| 98 |
output = pipe(
|
|
|
|
| 105 |
generator=generator,
|
| 106 |
)
|
| 107 |
logger.info("Pipeline inference finished")
|
| 108 |
+
if progress is not None:
|
| 109 |
+
progress(0.95, desc="Finalizing output...")
|
| 110 |
return output.images[0]
|