Update app.py
Browse files
app.py
CHANGED
|
@@ -273,18 +273,18 @@ 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 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
|
| 289 |
def get_prompt_from_theme(gender, theme):
|
| 290 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
|
@@ -482,7 +482,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 482 |
theme_buttons = []
|
| 483 |
for theme in list(man_prompts.keys()): # initially load man themes
|
| 484 |
btn = gr.Button(theme)
|
| 485 |
-
|
| 486 |
# theme_buttons.append(gr.Button(theme))
|
| 487 |
# prompt_buttons = []
|
| 488 |
# for s in suggestions:
|
|
@@ -512,7 +512,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 512 |
gender_selector.change(
|
| 513 |
fn=lambda gender: [gr.update(visible=True) for _ in theme_btns],
|
| 514 |
inputs=gender_selector,
|
| 515 |
-
outputs=
|
| 516 |
)
|
| 517 |
|
| 518 |
show_prompts_btn.click(
|
|
@@ -659,7 +659,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 659 |
# )
|
| 660 |
|
| 661 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|
| 662 |
-
for btn in
|
| 663 |
btn.click(
|
| 664 |
fn=lambda theme_name, g: get_prompt_from_theme(g, theme_name),
|
| 665 |
inputs=[btn, gender_selector],
|
|
|
|
| 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 get_prompt_from_theme(gender, theme):
|
| 290 |
return get_prompts_by_gender(gender)[theme], gr.update(visible=False)
|
|
|
|
| 482 |
theme_buttons = []
|
| 483 |
for theme in list(man_prompts.keys()): # initially load man themes
|
| 484 |
btn = gr.Button(theme)
|
| 485 |
+
theme_buttons.append(btn)
|
| 486 |
# theme_buttons.append(gr.Button(theme))
|
| 487 |
# prompt_buttons = []
|
| 488 |
# for s in suggestions:
|
|
|
|
| 512 |
gender_selector.change(
|
| 513 |
fn=lambda gender: [gr.update(visible=True) for _ in theme_btns],
|
| 514 |
inputs=gender_selector,
|
| 515 |
+
outputs=update_theme_buttons
|
| 516 |
)
|
| 517 |
|
| 518 |
show_prompts_btn.click(
|
|
|
|
| 659 |
# )
|
| 660 |
|
| 661 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|
| 662 |
+
for btn in theme_buttons:
|
| 663 |
btn.click(
|
| 664 |
fn=lambda theme_name, g: get_prompt_from_theme(g, theme_name),
|
| 665 |
inputs=[btn, gender_selector],
|