Update app.py
Browse filesbrought back logo
deleted the commented parts
app.py
CHANGED
|
@@ -296,28 +296,6 @@ def update_prompt_on_gender_change(gender, theme_name, current_prompt):
|
|
| 296 |
return [new_prompt] + button_updates
|
| 297 |
|
| 298 |
|
| 299 |
-
# # ✅ Place this here, above gr.Blocks
|
| 300 |
-
# def update_theme_buttons(gender):
|
| 301 |
-
# prompts = get_prompts_by_gender(gender)
|
| 302 |
-
# updates = []
|
| 303 |
-
# themes = list(prompts.keys())
|
| 304 |
-
|
| 305 |
-
# for i, theme in enumerate(themes):
|
| 306 |
-
# if i < len(theme_buttons):
|
| 307 |
-
# updates.append(gr.update(value=theme, visible=True))
|
| 308 |
-
# # hide extra buttons if any
|
| 309 |
-
# for j in range(len(themes), len(theme_buttons)):
|
| 310 |
-
# updates.append(gr.update(visible=False))
|
| 311 |
-
# return updates
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
# def update_theme_buttons(gender):
|
| 315 |
-
# prompts = man_prompts if gender == "man" else woman_prompts
|
| 316 |
-
# updates = []
|
| 317 |
-
# for theme in prompts.keys():
|
| 318 |
-
# updates.append(gr.update(value=theme, visible=True))
|
| 319 |
-
# return updates
|
| 320 |
-
|
| 321 |
def get_prompt_from_theme(gender, theme):
|
| 322 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
| 323 |
|
|
@@ -340,7 +318,7 @@ for i, btn in enumerate(theme_buttons):
|
|
| 340 |
|
| 341 |
|
| 342 |
### Description and style
|
| 343 |
-
|
| 344 |
# <center><img src='https://photo-maker.github.io/assets/logo.png' alt='PhotoMaker logo' style="width:80px; margin-bottom:10px"></center>
|
| 345 |
# """
|
| 346 |
# title = r"""
|
|
@@ -489,21 +467,13 @@ def update_prompt_buttons_visibility(gender):
|
|
| 489 |
# theme_buttons = []
|
| 490 |
|
| 491 |
with gr.Blocks(css=css) as demo:
|
| 492 |
-
|
| 493 |
# gr.Markdown(title)
|
| 494 |
gr.HTML(title_html)
|
| 495 |
#gr.Markdown(description)
|
| 496 |
|
| 497 |
selected_theme = gr.State("")
|
| 498 |
|
| 499 |
-
|
| 500 |
-
# current_suggestions = gr.State(woman_prompts)
|
| 501 |
-
|
| 502 |
-
# gr.DuplicateButton(
|
| 503 |
-
# value="Duplicate Space for private use ",
|
| 504 |
-
# elem_id="duplicate-button",
|
| 505 |
-
# visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
|
| 506 |
-
# )
|
| 507 |
with gr.Row():
|
| 508 |
with gr.Column():
|
| 509 |
|
|
@@ -515,15 +485,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 515 |
with gr.Column(visible=False, elem_id="reupload_wrapper") as clear_button:
|
| 516 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
| 517 |
|
| 518 |
-
# with gr.Column(visible=False) as clear_button:
|
| 519 |
-
# remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
| 520 |
-
# prompt = gr.Textbox(
|
| 521 |
-
# label="Prompt",
|
| 522 |
-
# info="Try something like 'a photo of a man/woman img', 'img' is the trigger word.",
|
| 523 |
-
# placeholder="A photo of a [man/woman img]..."
|
| 524 |
-
# interactive=False
|
| 525 |
-
# )
|
| 526 |
-
|
| 527 |
prompt = gr.Dropdown(
|
| 528 |
label="Select Prompt",
|
| 529 |
choices=list(get_prompts_by_gender("woman").values()), # default to woman
|
|
@@ -540,68 +501,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 540 |
|
| 541 |
|
| 542 |
with gr.Row():
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
# with gr.Group(visible=False, elem_id="prompt_suggestions_box") as prompt_suggestions:
|
| 546 |
-
# with gr.Column(elem_classes="scrollable-prompts"):
|
| 547 |
-
# gr.Markdown("### Suggested Prompts")
|
| 548 |
-
|
| 549 |
-
# theme_buttons = [gr.Button(theme, visible=False) for theme in man_prompts.keys()]
|
| 550 |
-
# for theme in man_prompts.keys():
|
| 551 |
-
# btn = gr.Button(theme, visible=False)
|
| 552 |
-
# theme_buttons.append(btn)
|
| 553 |
-
# btn.click(
|
| 554 |
-
# fn=lambda gender, t=theme: (get_prompts_by_gender(gender)[t], t, gr.update(visible=False)),
|
| 555 |
-
# inputs=gender_selector,
|
| 556 |
-
# outputs=[prompt, selected_theme, prompt_suggestions]
|
| 557 |
-
# )
|
| 558 |
-
|
| 559 |
-
# for theme, btn in zip(man_prompts.keys(), theme_buttons):
|
| 560 |
-
# btn.click(
|
| 561 |
-
# fn=lambda gender, t=theme: gr.update(value=get_prompts_by_gender(gender)[t]),
|
| 562 |
-
# inputs=gender_selector,
|
| 563 |
-
# outputs=prompt
|
| 564 |
-
# )
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
# theme_buttons.append(gr.Button(theme))
|
| 569 |
-
# prompt_buttons = []
|
| 570 |
-
# for s in suggestions:
|
| 571 |
-
# b = gr.Button(s)
|
| 572 |
-
# prompt_buttons.append((b, s))
|
| 573 |
-
|
| 574 |
-
# suggestion_buttons = [gr.Button(s) for s in current_suggestions.value]
|
| 575 |
-
# close_btn = gr.Button("❌ Close", elem_id="close_prompt_box")
|
| 576 |
-
|
| 577 |
-
# close_btn.click(
|
| 578 |
-
# fn=lambda: gr.update(visible=False),
|
| 579 |
-
# inputs=None,
|
| 580 |
-
# outputs=prompt_suggestions
|
| 581 |
-
# )
|
| 582 |
pass
|
| 583 |
|
| 584 |
-
|
| 585 |
-
# updates = update_prompt_buttons_visibility(gender)
|
| 586 |
-
# # Force popup to remain hidden
|
| 587 |
-
# updates[0] = gr.update(visible=False)
|
| 588 |
-
# return updates
|
| 589 |
-
|
| 590 |
-
# def update_buttons_and_show(gender):
|
| 591 |
-
# updates = update_prompt_buttons_visibility(gender)
|
| 592 |
-
# updates[0] = gr.update(visible=True) # force popup visible
|
| 593 |
-
# return updates
|
| 594 |
-
|
| 595 |
-
# def update_prompt_on_gender_change(gender, theme_name, current_prompt):
|
| 596 |
-
# button_updates = update_theme_buttons_only(gender)
|
| 597 |
-
# if theme_name and theme_name in get_prompts_by_gender(gender):
|
| 598 |
-
# # regenerate prompt for same theme but new gender
|
| 599 |
-
# new_prompt = get_prompts_by_gender(gender)[theme_name]
|
| 600 |
-
# else:
|
| 601 |
-
# new_prompt = current_prompt
|
| 602 |
-
# # ✅ return prompt first, then button updates (match outputs length)
|
| 603 |
-
# return [new_prompt] + button_updates
|
| 604 |
-
|
| 605 |
def update_prompt_dropdown(gender):
|
| 606 |
prompts = list(get_prompts_by_gender(gender).values())
|
| 607 |
return gr.update(choices=prompts, value=prompts[0]) # sets default to first
|
|
@@ -616,19 +519,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 616 |
outputs=prompt
|
| 617 |
)
|
| 618 |
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
# show_prompts_btn.click(
|
| 622 |
-
# # fn=lambda: gr.update(visible=True),
|
| 623 |
-
# fn=update_theme_buttons_only,
|
| 624 |
-
# inputs=gender_selector,
|
| 625 |
-
# outputs=theme_buttons
|
| 626 |
-
# ).then(
|
| 627 |
-
# lambda: gr.update(visible=True),
|
| 628 |
-
# outputs=prompt_suggestions
|
| 629 |
-
# )
|
| 630 |
-
|
| 631 |
-
|
| 632 |
style = gr.Dropdown(label="Style template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME, visible=False)
|
| 633 |
aspect_ratio = gr.Dropdown(label="Output aspect ratio", choices=ASPECT_RATIO_LABELS, value=DEFAULT_ASPECT_RATIO, visible=False)
|
| 634 |
submit = gr.Button("GENERATE" , elem_id="generate_btn")
|
|
@@ -751,18 +642,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 751 |
inputs=input_list,
|
| 752 |
outputs=[gallery, usage_tips]
|
| 753 |
)
|
| 754 |
-
|
| 755 |
-
# Show the suggestions popup
|
| 756 |
-
# show_prompts_btn.click(
|
| 757 |
-
# fn=lambda: gr.update(visible=True),
|
| 758 |
-
# outputs=prompt_suggestions
|
| 759 |
-
# )
|
| 760 |
-
|
| 761 |
-
# Close the popup
|
| 762 |
-
# close_btn.click(
|
| 763 |
-
# lambda: gr.update(visible=False),
|
| 764 |
-
# outputs=prompt_suggestions
|
| 765 |
-
# )
|
| 766 |
|
| 767 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|
| 768 |
for btn in theme_buttons:
|
|
|
|
| 296 |
return [new_prompt] + button_updates
|
| 297 |
|
| 298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
def get_prompt_from_theme(gender, theme):
|
| 300 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
| 301 |
|
|
|
|
| 318 |
|
| 319 |
|
| 320 |
### Description and style
|
| 321 |
+
logo = r"""
|
| 322 |
# <center><img src='https://photo-maker.github.io/assets/logo.png' alt='PhotoMaker logo' style="width:80px; margin-bottom:10px"></center>
|
| 323 |
# """
|
| 324 |
# title = r"""
|
|
|
|
| 467 |
# theme_buttons = []
|
| 468 |
|
| 469 |
with gr.Blocks(css=css) as demo:
|
| 470 |
+
gr.Markdown(logo)
|
| 471 |
# gr.Markdown(title)
|
| 472 |
gr.HTML(title_html)
|
| 473 |
#gr.Markdown(description)
|
| 474 |
|
| 475 |
selected_theme = gr.State("")
|
| 476 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
with gr.Row():
|
| 478 |
with gr.Column():
|
| 479 |
|
|
|
|
| 485 |
with gr.Column(visible=False, elem_id="reupload_wrapper") as clear_button:
|
| 486 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
| 487 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
prompt = gr.Dropdown(
|
| 489 |
label="Select Prompt",
|
| 490 |
choices=list(get_prompts_by_gender("woman").values()), # default to woman
|
|
|
|
| 501 |
|
| 502 |
|
| 503 |
with gr.Row():
|
| 504 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
pass
|
| 506 |
|
| 507 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
def update_prompt_dropdown(gender):
|
| 509 |
prompts = list(get_prompts_by_gender(gender).values())
|
| 510 |
return gr.update(choices=prompts, value=prompts[0]) # sets default to first
|
|
|
|
| 519 |
outputs=prompt
|
| 520 |
)
|
| 521 |
|
| 522 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
style = gr.Dropdown(label="Style template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME, visible=False)
|
| 524 |
aspect_ratio = gr.Dropdown(label="Output aspect ratio", choices=ASPECT_RATIO_LABELS, value=DEFAULT_ASPECT_RATIO, visible=False)
|
| 525 |
submit = gr.Button("GENERATE" , elem_id="generate_btn")
|
|
|
|
| 642 |
inputs=input_list,
|
| 643 |
outputs=[gallery, usage_tips]
|
| 644 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
|
| 646 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|
| 647 |
for btn in theme_buttons:
|