Skip to content

Commit

Permalink
style: accordion
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyi-Lin committed Sep 10, 2024
1 parent a956814 commit 28e861e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
20 changes: 18 additions & 2 deletions demo/locals.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,20 @@
"label": "高清照",
},
},
"standard_photo_png": {
"en": {
"label": "Matting Standard photo",
},
"zh": {
"label": "透明标准照",
},
},
"hd_photo_png": {
"en": {
"label": "Matting photo",
"label": "Matting HD photo",
},
"zh": {
"label": "透明图",
"label": "透明高清照",
},
},
"layout_photo": {
Expand All @@ -276,4 +284,12 @@
"label": "下载调整 KB 大小后的照片",
},
},
"matting_image": {
"en": {
"label": "Matting image",
},
"zh": {
"label": "抠图图像",
},
},
}
5 changes: 5 additions & 0 deletions demo/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def process(

else:
(result_image_standard, result_image_hd, _, _) = result

result_image_standard_png = np.uint8(result_image_standard)
result_image_hd_png = np.uint8(result_image_hd)

if (
idphoto_json["render_mode"]
== LOCALES["render_mode"][language]["choices"][0]
Expand Down Expand Up @@ -274,6 +277,7 @@ def process(
return [
result_image_standard, # img_output_standard
result_image_hd, # img_output_standard_hd
result_image_standard_png, # img_output_standard_hd_png
result_image_hd_png, # img_output_standard_hd_png
result_layout_image, # img_output_layout
gr.update(visible=False), # notification
Expand All @@ -283,6 +287,7 @@ def process(
return [
result_image_standard, # img_output_standard
result_image_hd, # img_output_standard_hd
result_image_standard_png, # img_output_standard_hd_png
result_image_hd_png, # img_output_standard_hd_png
result_layout_image, # img_output_layout
gr.update(visible=False), # notification
Expand Down
33 changes: 27 additions & 6 deletions demo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,34 @@ def update_watermark_text_visibility(choice, language):
height=350,
format="jpeg",
)
img_output_standard_hd_png = gr.Image(
label=LOCALES["hd_photo_png"][DEFAULT_LANG]["label"],
height=350,
format="png",
elem_id="hd_photo_png",
)

img_output_layout = gr.Image(
label=LOCALES["layout_photo"][DEFAULT_LANG]["label"],
height=350,
format="jpeg",
)

file_download = gr.File(
label=LOCALES["download"][DEFAULT_LANG]["label"], visible=False
)

with gr.Accordion(
LOCALES["matting_image"][DEFAULT_LANG]["label"], open=False
) as matting_image_accordion:
with gr.Row():
img_output_standard_png = gr.Image(
label=LOCALES["standard_photo_png"][DEFAULT_LANG]["label"],
height=350,
format="png",
elem_id="standard_photo_png",
)
img_output_standard_hd_png = gr.Image(
label=LOCALES["hd_photo_png"][DEFAULT_LANG]["label"],
height=350,
format="png",
elem_id="hd_photo_png",
)

# ---------------- 设置隐藏/显示组件 ----------------
def change_language(language):
return {
Expand Down Expand Up @@ -310,6 +322,9 @@ def change_language(language):
img_output_standard_hd: gr.update(
label=LOCALES["hd_photo"][language]["label"]
),
img_output_standard_png: gr.update(
label=LOCALES["standard_photo_png"][language]["label"]
),
img_output_standard_hd_png: gr.update(
label=LOCALES["hd_photo_png"][language]["label"]
),
Expand Down Expand Up @@ -358,6 +373,9 @@ def change_language(language):
choices=LOCALES["watermark_switch"][language]["choices"],
value=LOCALES["watermark_switch"][language]["choices"][0],
),
matting_image_accordion: gr.update(
label=LOCALES["matting_image"][language]["label"]
),
}

def change_color(colors):
Expand Down Expand Up @@ -412,6 +430,7 @@ def change_image_kb(image_kb_option):
notification,
img_output_standard,
img_output_standard_hd,
img_output_standard_png,
img_output_standard_hd_png,
img_output_layout,
file_download,
Expand All @@ -427,6 +446,7 @@ def change_image_kb(image_kb_option):
watermark_text_angle,
watermark_text_space,
watermark_options,
matting_image_accordion,
],
)

Expand Down Expand Up @@ -475,6 +495,7 @@ def change_image_kb(image_kb_option):
outputs=[
img_output_standard,
img_output_standard_hd,
img_output_standard_png,
img_output_standard_hd_png,
img_output_layout,
notification,
Expand Down

0 comments on commit 28e861e

Please sign in to comment.