Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,9 +38,9 @@ dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
|
|
| 38 |
STYLE_NAMES = list(styles.keys())
|
| 39 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 40 |
enable_lcm_arg = False
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
# download checkpoints
|
| 46 |
from huggingface_hub import hf_hub_download
|
|
@@ -235,10 +235,7 @@ def generate_image(
|
|
| 235 |
num_steps,
|
| 236 |
identitynet_strength_ratio,
|
| 237 |
adapter_strength_ratio,
|
| 238 |
-
pose_strength,
|
| 239 |
-
canny_strength,
|
| 240 |
depth_strength,
|
| 241 |
-
controlnet_selection,
|
| 242 |
guidance_scale,
|
| 243 |
seed,
|
| 244 |
scheduler,
|
|
@@ -246,6 +243,9 @@ def generate_image(
|
|
| 246 |
enhance_face_region,
|
| 247 |
progress=gr.Progress(track_tqdm=True),
|
| 248 |
):
|
|
|
|
|
|
|
|
|
|
| 249 |
face_image_path = "./examples/fingicode.jpg"
|
| 250 |
|
| 251 |
if enable_LCM:
|
|
@@ -414,24 +414,18 @@ css = """
|
|
| 414 |
.gradio-container {width: 85% !important}
|
| 415 |
"""
|
| 416 |
with gr.Blocks(css=css) as demo:
|
| 417 |
-
# description
|
| 418 |
gr.Markdown(title)
|
| 419 |
gr.Markdown(description)
|
| 420 |
|
| 421 |
with gr.Row():
|
| 422 |
with gr.Column():
|
| 423 |
with gr.Row(equal_height=True):
|
| 424 |
-
# upload
|
| 425 |
-
# face_file = gr.Image(
|
| 426 |
-
# label="Upload a photo of your face", type="filepath"
|
| 427 |
-
# )
|
| 428 |
-
# optional: upload a reference image
|
| 429 |
pose_file = gr.Image(
|
| 430 |
label="Upload a reference pose image (Optional)",
|
| 431 |
type="filepath",
|
| 432 |
)
|
| 433 |
|
| 434 |
-
# prompt
|
| 435 |
prompt = gr.Textbox(
|
| 436 |
label="Prompt",
|
| 437 |
info="Give simple prompt is enough to achieve good face fidelity",
|
|
@@ -440,18 +434,18 @@ with gr.Blocks(css=css) as demo:
|
|
| 440 |
)
|
| 441 |
|
| 442 |
submit = gr.Button("Submit", variant="primary")
|
| 443 |
-
|
| 444 |
enable_LCM = gr.Checkbox(
|
| 445 |
label="Enable Fast Inference with LCM", value=enable_lcm_arg,
|
| 446 |
info="LCM speeds up the inference step, the trade-off is the quality of the generated image. It performs better with portrait face images rather than distant faces",
|
| 447 |
)
|
|
|
|
| 448 |
style = gr.Dropdown(
|
| 449 |
label="Style template",
|
| 450 |
choices=STYLE_NAMES,
|
| 451 |
value=DEFAULT_STYLE_NAME,
|
| 452 |
)
|
| 453 |
|
| 454 |
-
# strength
|
| 455 |
identitynet_strength_ratio = gr.Slider(
|
| 456 |
label="IdentityNet strength (for fidelity)",
|
| 457 |
minimum=0,
|
|
@@ -459,6 +453,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 459 |
step=0.05,
|
| 460 |
value=0.80,
|
| 461 |
)
|
|
|
|
| 462 |
adapter_strength_ratio = gr.Slider(
|
| 463 |
label="Image adapter strength (for detail)",
|
| 464 |
minimum=0,
|
|
@@ -466,32 +461,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 466 |
step=0.05,
|
| 467 |
value=0.80,
|
| 468 |
)
|
| 469 |
-
with gr.Accordion("Controlnet"):
|
| 470 |
-
controlnet_selection = gr.CheckboxGroup(
|
| 471 |
-
["pose", "canny", "depth"], label="Controlnet", value=["pose"],
|
| 472 |
-
info="Use pose for skeleton inference, canny for edge detection, and depth for depth map estimation. You can try all three to control the generation process"
|
| 473 |
-
)
|
| 474 |
-
pose_strength = gr.Slider(
|
| 475 |
-
label="Pose strength",
|
| 476 |
-
minimum=0,
|
| 477 |
-
maximum=1.5,
|
| 478 |
-
step=0.05,
|
| 479 |
-
value=0.40,
|
| 480 |
-
)
|
| 481 |
-
canny_strength = gr.Slider(
|
| 482 |
-
label="Canny strength",
|
| 483 |
-
minimum=0,
|
| 484 |
-
maximum=1.5,
|
| 485 |
-
step=0.05,
|
| 486 |
-
value=0.40,
|
| 487 |
-
)
|
| 488 |
-
depth_strength = gr.Slider(
|
| 489 |
-
label="Depth strength",
|
| 490 |
-
minimum=0,
|
| 491 |
-
maximum=1.5,
|
| 492 |
-
step=0.05,
|
| 493 |
-
value=0.40,
|
| 494 |
-
)
|
| 495 |
with gr.Accordion(open=False, label="Advanced Options"):
|
| 496 |
negative_prompt = gr.Textbox(
|
| 497 |
label="Negative Prompt",
|
|
@@ -551,10 +520,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 551 |
num_steps,
|
| 552 |
identitynet_strength_ratio,
|
| 553 |
adapter_strength_ratio,
|
| 554 |
-
pose_strength,
|
| 555 |
-
canny_strength,
|
| 556 |
depth_strength,
|
| 557 |
-
|
| 558 |
guidance_scale,
|
| 559 |
seed,
|
| 560 |
scheduler,
|
|
@@ -571,15 +538,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 571 |
queue=False,
|
| 572 |
)
|
| 573 |
|
| 574 |
-
# gr.Examples(
|
| 575 |
-
# examples=get_example(),
|
| 576 |
-
# inputs=[face_file, pose_file, prompt, style, negative_prompt],
|
| 577 |
-
# fn=run_for_examples,
|
| 578 |
-
# outputs=[gallery, usage_tips],
|
| 579 |
-
# cache_examples=True,
|
| 580 |
-
# )
|
| 581 |
-
|
| 582 |
-
# gr.Markdown(article)
|
| 583 |
-
|
| 584 |
demo.queue(api_open=False)
|
| 585 |
demo.launch()
|
|
|
|
| 38 |
STYLE_NAMES = list(styles.keys())
|
| 39 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 40 |
enable_lcm_arg = False
|
| 41 |
+
DEFAULT_POSE_STRENGTH = 1.0
|
| 42 |
+
DEFAULT_CANNY_STRENGTH = 0.4
|
| 43 |
+
CONTROLNET_SELECTION = ["pose", "canny"]
|
| 44 |
|
| 45 |
# download checkpoints
|
| 46 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 235 |
num_steps,
|
| 236 |
identitynet_strength_ratio,
|
| 237 |
adapter_strength_ratio,
|
|
|
|
|
|
|
| 238 |
depth_strength,
|
|
|
|
| 239 |
guidance_scale,
|
| 240 |
seed,
|
| 241 |
scheduler,
|
|
|
|
| 243 |
enhance_face_region,
|
| 244 |
progress=gr.Progress(track_tqdm=True),
|
| 245 |
):
|
| 246 |
+
pose_strength = DEFAULT_POSE_STRENGTH
|
| 247 |
+
canny_strength = DEFAULT_CANNY_STRENGTH
|
| 248 |
+
controlnet_selection = CONTROLNET_SELECTION
|
| 249 |
face_image_path = "./examples/fingicode.jpg"
|
| 250 |
|
| 251 |
if enable_LCM:
|
|
|
|
| 414 |
.gradio-container {width: 85% !important}
|
| 415 |
"""
|
| 416 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 417 |
gr.Markdown(title)
|
| 418 |
gr.Markdown(description)
|
| 419 |
|
| 420 |
with gr.Row():
|
| 421 |
with gr.Column():
|
| 422 |
with gr.Row(equal_height=True):
|
| 423 |
+
# Optional: upload a reference image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
pose_file = gr.Image(
|
| 425 |
label="Upload a reference pose image (Optional)",
|
| 426 |
type="filepath",
|
| 427 |
)
|
| 428 |
|
|
|
|
| 429 |
prompt = gr.Textbox(
|
| 430 |
label="Prompt",
|
| 431 |
info="Give simple prompt is enough to achieve good face fidelity",
|
|
|
|
| 434 |
)
|
| 435 |
|
| 436 |
submit = gr.Button("Submit", variant="primary")
|
| 437 |
+
|
| 438 |
enable_LCM = gr.Checkbox(
|
| 439 |
label="Enable Fast Inference with LCM", value=enable_lcm_arg,
|
| 440 |
info="LCM speeds up the inference step, the trade-off is the quality of the generated image. It performs better with portrait face images rather than distant faces",
|
| 441 |
)
|
| 442 |
+
|
| 443 |
style = gr.Dropdown(
|
| 444 |
label="Style template",
|
| 445 |
choices=STYLE_NAMES,
|
| 446 |
value=DEFAULT_STYLE_NAME,
|
| 447 |
)
|
| 448 |
|
|
|
|
| 449 |
identitynet_strength_ratio = gr.Slider(
|
| 450 |
label="IdentityNet strength (for fidelity)",
|
| 451 |
minimum=0,
|
|
|
|
| 453 |
step=0.05,
|
| 454 |
value=0.80,
|
| 455 |
)
|
| 456 |
+
|
| 457 |
adapter_strength_ratio = gr.Slider(
|
| 458 |
label="Image adapter strength (for detail)",
|
| 459 |
minimum=0,
|
|
|
|
| 461 |
step=0.05,
|
| 462 |
value=0.80,
|
| 463 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
with gr.Accordion(open=False, label="Advanced Options"):
|
| 465 |
negative_prompt = gr.Textbox(
|
| 466 |
label="Negative Prompt",
|
|
|
|
| 520 |
num_steps,
|
| 521 |
identitynet_strength_ratio,
|
| 522 |
adapter_strength_ratio,
|
|
|
|
|
|
|
| 523 |
depth_strength,
|
| 524 |
+
CONTROLNET_SELECTION,
|
| 525 |
guidance_scale,
|
| 526 |
seed,
|
| 527 |
scheduler,
|
|
|
|
| 538 |
queue=False,
|
| 539 |
)
|
| 540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
demo.queue(api_open=False)
|
| 542 |
demo.launch()
|