Spaces:
Running on Zero
Running on Zero
Tianshuo-Xu commited on
Commit ·
375cc31
1
Parent(s): 76d0cdd
Update UI with dynamic + button for adding combinations
Browse files
app.py
CHANGED
|
@@ -443,8 +443,9 @@ with gr.Blocks(title="UniCalli - Chinese Calligraphy Generator / 中国书法生
|
|
| 443 |
max_lines=1
|
| 444 |
)
|
| 445 |
|
| 446 |
-
gr.Markdown("### 👤 书法家与字体组合 / Calligraphers & Fonts
|
| 447 |
|
|
|
|
| 448 |
author_dropdowns = []
|
| 449 |
font_dropdowns = []
|
| 450 |
|
|
@@ -456,9 +457,11 @@ with gr.Blocks(title="UniCalli - Chinese Calligraphy Generator / 中国书法生
|
|
| 456 |
else:
|
| 457 |
default_font = initial_font_choices[0] if initial_font_choices else "草 (Cursive Script)"
|
| 458 |
|
|
|
|
|
|
|
| 459 |
for i in range(4):
|
| 460 |
-
with gr.Group():
|
| 461 |
-
gr.Markdown(f"**组合 {i+1} / Combination {i+1}**
|
| 462 |
with gr.Row():
|
| 463 |
a_drop = gr.Dropdown(
|
| 464 |
label=f"书法家 / Calligrapher",
|
|
@@ -472,6 +475,10 @@ with gr.Blocks(title="UniCalli - Chinese Calligraphy Generator / 中国书法生
|
|
| 472 |
)
|
| 473 |
author_dropdowns.append(a_drop)
|
| 474 |
font_dropdowns.append(f_drop)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 475 |
|
| 476 |
gr.Markdown("### ⚙️ 生成设置 / Generation Settings")
|
| 477 |
|
|
@@ -549,6 +556,20 @@ with gr.Blocks(title="UniCalli - Chinese Calligraphy Generator / 中国书法生
|
|
| 549 |
inputs=[author_dropdowns[i]],
|
| 550 |
outputs=[font_dropdowns[i]]
|
| 551 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
# Prepare inputs list for the interactive session
|
| 554 |
session_inputs = [text_input]
|
|
|
|
| 443 |
max_lines=1
|
| 444 |
)
|
| 445 |
|
| 446 |
+
gr.Markdown("### 👤 书法家与字体组合 / Calligraphers & Fonts")
|
| 447 |
|
| 448 |
+
combo_groups = []
|
| 449 |
author_dropdowns = []
|
| 450 |
font_dropdowns = []
|
| 451 |
|
|
|
|
| 457 |
else:
|
| 458 |
default_font = initial_font_choices[0] if initial_font_choices else "草 (Cursive Script)"
|
| 459 |
|
| 460 |
+
active_count_state = gr.State(value=1)
|
| 461 |
+
|
| 462 |
for i in range(4):
|
| 463 |
+
with gr.Group(visible=(i == 0)) as group:
|
| 464 |
+
gr.Markdown(f"**组合 {i+1} / Combination {i+1}**")
|
| 465 |
with gr.Row():
|
| 466 |
a_drop = gr.Dropdown(
|
| 467 |
label=f"书法家 / Calligrapher",
|
|
|
|
| 475 |
)
|
| 476 |
author_dropdowns.append(a_drop)
|
| 477 |
font_dropdowns.append(f_drop)
|
| 478 |
+
combo_groups.append(group)
|
| 479 |
+
|
| 480 |
+
add_combo_btn = gr.Button("➕ 添加书法家与风格组合 / Add Combination", size="sm")
|
| 481 |
+
|
| 482 |
|
| 483 |
gr.Markdown("### ⚙️ 生成设置 / Generation Settings")
|
| 484 |
|
|
|
|
| 556 |
inputs=[author_dropdowns[i]],
|
| 557 |
outputs=[font_dropdowns[i]]
|
| 558 |
)
|
| 559 |
+
|
| 560 |
+
def add_combo(current_count):
|
| 561 |
+
new_count = min(current_count + 1, 4)
|
| 562 |
+
updates = []
|
| 563 |
+
for i in range(4):
|
| 564 |
+
updates.append(gr.update(visible=(i < new_count)))
|
| 565 |
+
updates.append(gr.update(interactive=(new_count < 4)))
|
| 566 |
+
return [new_count] + updates
|
| 567 |
+
|
| 568 |
+
add_combo_btn.click(
|
| 569 |
+
fn=add_combo,
|
| 570 |
+
inputs=[active_count_state],
|
| 571 |
+
outputs=[active_count_state] + combo_groups + [add_combo_btn]
|
| 572 |
+
)
|
| 573 |
|
| 574 |
# Prepare inputs list for the interactive session
|
| 575 |
session_inputs = [text_input]
|