Update app.py
Browse files
app.py
CHANGED
|
@@ -470,6 +470,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 470 |
gr.HTML(title_html)
|
| 471 |
#gr.Markdown(description)
|
| 472 |
|
|
|
|
|
|
|
|
|
|
| 473 |
# current_suggestions = gr.State(woman_prompts)
|
| 474 |
|
| 475 |
# gr.DuplicateButton(
|
|
@@ -510,9 +513,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 510 |
gr.Markdown("### Suggested Prompts")
|
| 511 |
|
| 512 |
# theme_buttons = [gr.Button(theme, visible=False) for theme in man_prompts.keys()]
|
| 513 |
-
for theme in man_prompts.keys():
|
| 514 |
-
|
| 515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
# theme_buttons.append(gr.Button(theme))
|
| 517 |
# prompt_buttons = []
|
| 518 |
# for s in suggestions:
|
|
@@ -539,11 +548,20 @@ with gr.Blocks(css=css) as demo:
|
|
| 539 |
# updates[0] = gr.update(visible=True) # force popup visible
|
| 540 |
# return updates
|
| 541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
gender_selector.change(
|
| 543 |
-
fn=
|
| 544 |
-
inputs=gender_selector,
|
| 545 |
-
outputs=theme_buttons
|
| 546 |
)
|
|
|
|
| 547 |
|
| 548 |
show_prompts_btn.click(
|
| 549 |
# fn=lambda: gr.update(visible=True),
|
|
|
|
| 470 |
gr.HTML(title_html)
|
| 471 |
#gr.Markdown(description)
|
| 472 |
|
| 473 |
+
selected_theme = gr.State("")
|
| 474 |
+
|
| 475 |
+
|
| 476 |
# current_suggestions = gr.State(woman_prompts)
|
| 477 |
|
| 478 |
# gr.DuplicateButton(
|
|
|
|
| 513 |
gr.Markdown("### Suggested Prompts")
|
| 514 |
|
| 515 |
# theme_buttons = [gr.Button(theme, visible=False) for theme in man_prompts.keys()]
|
| 516 |
+
for theme in man_prompts.keys():
|
| 517 |
+
btn = gr.Button(theme, visible=False)
|
| 518 |
+
theme_buttons.append(btn)
|
| 519 |
+
btn.click(
|
| 520 |
+
fn=lambda gender, t=theme: (get_prompts_by_gender(gender)[t], t, gr.update(visible=False)),
|
| 521 |
+
inputs=gender_selector,
|
| 522 |
+
outputs=[prompt, selected_theme, prompt_suggestions]
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
# theme_buttons.append(gr.Button(theme))
|
| 526 |
# prompt_buttons = []
|
| 527 |
# for s in suggestions:
|
|
|
|
| 548 |
# updates[0] = gr.update(visible=True) # force popup visible
|
| 549 |
# return updates
|
| 550 |
|
| 551 |
+
def update_prompt_on_gender_change(gender, theme_name, current_prompt):
|
| 552 |
+
if theme_name and theme_name in get_prompts_by_gender(gender):
|
| 553 |
+
# regenerate the prompt for the same theme but with new gender
|
| 554 |
+
new_prompt = get_prompts_by_gender(gender)[theme_name]
|
| 555 |
+
return new_prompt, update_theme_buttons_only(gender)
|
| 556 |
+
# if no theme selected, keep existing prompt
|
| 557 |
+
return current_prompt, update_theme_buttons_only(gender)
|
| 558 |
+
|
| 559 |
gender_selector.change(
|
| 560 |
+
fn=update_prompt_on_gender_change,
|
| 561 |
+
inputs=[gender_selector, selected_theme, prompt],
|
| 562 |
+
outputs=[prompt] + theme_buttons
|
| 563 |
)
|
| 564 |
+
|
| 565 |
|
| 566 |
show_prompts_btn.click(
|
| 567 |
# fn=lambda: gr.update(visible=True),
|