Update app.py
Browse files
app.py
CHANGED
|
@@ -273,26 +273,28 @@ def get_prompts_by_gender(gender):
|
|
| 273 |
return man_prompts if gender == "man" else woman_prompts
|
| 274 |
|
| 275 |
# ✅ Place this here, above gr.Blocks
|
| 276 |
-
# def update_theme_buttons(gender):
|
| 277 |
-
# prompts = get_prompts_by_gender(gender) # returns {theme: prompt}
|
| 278 |
-
# updates = []
|
| 279 |
-
# for i, (theme, prompt_text) in enumerate(prompts.items()):
|
| 280 |
-
# if i < len(theme_btns):
|
| 281 |
-
# updates.append(gr.update(value=theme, visible=True))
|
| 282 |
-
# else:
|
| 283 |
-
# break
|
| 284 |
-
# # Hide remaining unused buttons
|
| 285 |
-
# for j in range(len(prompts), len(theme_btns)):
|
| 286 |
-
# updates.append(gr.update(visible=False))
|
| 287 |
-
# return updates
|
| 288 |
-
|
| 289 |
def update_theme_buttons(gender):
|
| 290 |
-
prompts =
|
| 291 |
updates = []
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
return updates
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
def get_prompt_from_theme(gender, theme):
|
| 297 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
| 298 |
|
|
@@ -301,6 +303,16 @@ def update_suggestion_buttons(gender):
|
|
| 301 |
prompts = get_prompts_by_gender(gender)
|
| 302 |
return gr.update(visible=True), prompts
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
|
| 306 |
### Description and style
|
|
@@ -486,7 +498,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 486 |
with gr.Group(visible=False, elem_id="prompt_suggestions_box") as prompt_suggestions:
|
| 487 |
gr.Markdown("### Suggested Prompts")
|
| 488 |
|
| 489 |
-
theme_buttons = []
|
| 490 |
for theme in list(man_prompts.keys()): # initially load man themes
|
| 491 |
btn = gr.Button(theme)
|
| 492 |
theme_buttons.append(btn)
|
|
@@ -517,9 +529,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 517 |
# return updates
|
| 518 |
|
| 519 |
gender_selector.change(
|
| 520 |
-
fn=
|
| 521 |
inputs=gender_selector,
|
| 522 |
-
outputs=
|
| 523 |
)
|
| 524 |
|
| 525 |
show_prompts_btn.click(
|
|
@@ -657,10 +669,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 657 |
)
|
| 658 |
|
| 659 |
# Show the suggestions popup
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
|
| 665 |
# Close the popup
|
| 666 |
# close_btn.click(
|
|
|
|
| 273 |
return man_prompts if gender == "man" else woman_prompts
|
| 274 |
|
| 275 |
# ✅ Place this here, above gr.Blocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
def update_theme_buttons(gender):
|
| 277 |
+
prompts = get_prompts_by_gender(gender)
|
| 278 |
updates = []
|
| 279 |
+
themes = list(prompts.keys())
|
| 280 |
+
|
| 281 |
+
for i, btn in enumerate(theme_buttons):
|
| 282 |
+
theme = list(man_prompts.keys())[i]
|
| 283 |
+
btn.click(
|
| 284 |
+
fn=make_click_fn(theme),
|
| 285 |
+
inputs=gender_selector,
|
| 286 |
+
outputs=[prompt, prompt_suggestions]
|
| 287 |
+
)
|
| 288 |
return updates
|
| 289 |
|
| 290 |
+
|
| 291 |
+
# def update_theme_buttons(gender):
|
| 292 |
+
# prompts = man_prompts if gender == "man" else woman_prompts
|
| 293 |
+
# updates = []
|
| 294 |
+
# for theme in prompts.keys():
|
| 295 |
+
# updates.append(gr.update(value=theme, visible=True))
|
| 296 |
+
# return updates
|
| 297 |
+
|
| 298 |
def get_prompt_from_theme(gender, theme):
|
| 299 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
| 300 |
|
|
|
|
| 303 |
prompts = get_prompts_by_gender(gender)
|
| 304 |
return gr.update(visible=True), prompts
|
| 305 |
|
| 306 |
+
def make_click_fn(theme_name):
|
| 307 |
+
return lambda gender: get_prompt_from_theme(gender, theme_name)
|
| 308 |
+
|
| 309 |
+
for i, btn in enumerate(theme_buttons):
|
| 310 |
+
theme = list(man_prompts.keys())[i]
|
| 311 |
+
btn.click(
|
| 312 |
+
fn=make_click_fn(theme),
|
| 313 |
+
inputs=gender_selector,
|
| 314 |
+
outputs=[prompt, prompt_suggestions]
|
| 315 |
+
)
|
| 316 |
|
| 317 |
|
| 318 |
### Description and style
|
|
|
|
| 498 |
with gr.Group(visible=False, elem_id="prompt_suggestions_box") as prompt_suggestions:
|
| 499 |
gr.Markdown("### Suggested Prompts")
|
| 500 |
|
| 501 |
+
theme_buttons = [gr.Button(theme, visible=False) for theme in man_prompts.keys()]
|
| 502 |
for theme in list(man_prompts.keys()): # initially load man themes
|
| 503 |
btn = gr.Button(theme)
|
| 504 |
theme_buttons.append(btn)
|
|
|
|
| 529 |
# return updates
|
| 530 |
|
| 531 |
gender_selector.change(
|
| 532 |
+
fn=update_theme_buttons,
|
| 533 |
inputs=gender_selector,
|
| 534 |
+
outputs=theme_buttons
|
| 535 |
)
|
| 536 |
|
| 537 |
show_prompts_btn.click(
|
|
|
|
| 669 |
)
|
| 670 |
|
| 671 |
# Show the suggestions popup
|
| 672 |
+
show_prompts_btn.click(
|
| 673 |
+
fn=lambda: gr.update(visible=True),
|
| 674 |
+
outputs=prompt_suggestions
|
| 675 |
+
)
|
| 676 |
|
| 677 |
# Close the popup
|
| 678 |
# close_btn.click(
|