Spaces:
Running
Running
TheEeeeLin
commited on
Commit
•
3cdc8a1
1
Parent(s):
796a686
Update app.py
Browse files
app.py
CHANGED
@@ -62,10 +62,13 @@ def idphoto_inference(
|
|
62 |
matting_model_option,
|
63 |
face_detect_option,
|
64 |
head_measure_ratio=0.2,
|
65 |
-
head_height_ratio=0.45,
|
66 |
top_distance_max=0.12,
|
67 |
top_distance_min=0.10,
|
68 |
):
|
|
|
|
|
|
|
69 |
idphoto_json = {
|
70 |
"size_mode": mode_option,
|
71 |
"color_mode": color_option,
|
@@ -163,7 +166,8 @@ def idphoto_inference(
|
|
163 |
change_bg_only=change_bg_only,
|
164 |
size=idphoto_json["size"],
|
165 |
head_measure_ratio=head_measure_ratio,
|
166 |
-
head_height_ratio=head_height_ratio,
|
|
|
167 |
)
|
168 |
except FaceError:
|
169 |
result_message = {
|
@@ -390,66 +394,86 @@ if __name__ == "__main__":
|
|
390 |
elem_id="matting_model",
|
391 |
)
|
392 |
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
# 预设尺寸下拉菜单
|
401 |
-
with gr.Row(visible=True) as size_list_row:
|
402 |
-
size_list_options = gr.Dropdown(
|
403 |
-
choices=size_list_CN,
|
404 |
-
label="预设尺寸",
|
405 |
-
value=size_list_CN[0],
|
406 |
-
elem_id="size_list",
|
407 |
)
|
408 |
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
|
|
416 |
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
|
|
|
|
|
|
421 |
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
custom_color_B = gr.Number(value=0, label="B", interactive=True)
|
427 |
-
|
428 |
-
# 左:渲染方式选项
|
429 |
-
render_options = gr.Radio(
|
430 |
-
choices=render_CN,
|
431 |
-
label="渲染方式",
|
432 |
-
value="纯色",
|
433 |
-
elem_id="render",
|
434 |
-
)
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
minimum=
|
448 |
-
maximum=
|
449 |
-
value=
|
450 |
-
|
|
|
451 |
interactive=True,
|
452 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
img_but = gr.Button("开始制作")
|
455 |
|
@@ -520,6 +544,10 @@ if __name__ == "__main__":
|
|
520 |
img_output_standard_hd: gr.update(label="高清照"),
|
521 |
img_output_layout: gr.update(label="六寸排版照"),
|
522 |
file_download: gr.update(label="下载调整 KB 大小后的照片"),
|
|
|
|
|
|
|
|
|
523 |
}
|
524 |
|
525 |
elif language == "English":
|
@@ -560,6 +588,10 @@ if __name__ == "__main__":
|
|
560 |
file_download: gr.update(
|
561 |
label="Download the photo after adjusting the KB size"
|
562 |
),
|
|
|
|
|
|
|
|
|
563 |
}
|
564 |
|
565 |
def change_color(colors):
|
@@ -616,6 +648,10 @@ if __name__ == "__main__":
|
|
616 |
img_output_standard_hd,
|
617 |
img_output_layout,
|
618 |
file_download,
|
|
|
|
|
|
|
|
|
619 |
],
|
620 |
)
|
621 |
|
@@ -651,6 +687,8 @@ if __name__ == "__main__":
|
|
651 |
language_options,
|
652 |
matting_model_options,
|
653 |
face_detect_model_options,
|
|
|
|
|
654 |
],
|
655 |
outputs=[
|
656 |
img_output_standard,
|
|
|
62 |
matting_model_option,
|
63 |
face_detect_option,
|
64 |
head_measure_ratio=0.2,
|
65 |
+
# head_height_ratio=0.45,
|
66 |
top_distance_max=0.12,
|
67 |
top_distance_min=0.10,
|
68 |
):
|
69 |
+
|
70 |
+
top_distance_min = top_distance_max - 0.02
|
71 |
+
|
72 |
idphoto_json = {
|
73 |
"size_mode": mode_option,
|
74 |
"color_mode": color_option,
|
|
|
166 |
change_bg_only=change_bg_only,
|
167 |
size=idphoto_json["size"],
|
168 |
head_measure_ratio=head_measure_ratio,
|
169 |
+
# head_height_ratio=head_height_ratio,
|
170 |
+
head_top_range=(top_distance_max, top_distance_min),
|
171 |
)
|
172 |
except FaceError:
|
173 |
result_message = {
|
|
|
394 |
elem_id="matting_model",
|
395 |
)
|
396 |
|
397 |
+
with gr.Tab("核心参数") as key_parameter_tab:
|
398 |
+
mode_options = gr.Radio(
|
399 |
+
choices=size_mode_CN,
|
400 |
+
label="证件照尺寸选项",
|
401 |
+
value="尺寸列表",
|
402 |
+
elem_id="size",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
)
|
404 |
|
405 |
+
# 预设尺寸下拉菜单
|
406 |
+
with gr.Row(visible=True) as size_list_row:
|
407 |
+
size_list_options = gr.Dropdown(
|
408 |
+
choices=size_list_CN,
|
409 |
+
label="预设尺寸",
|
410 |
+
value=size_list_CN[0],
|
411 |
+
elem_id="size_list",
|
412 |
+
)
|
413 |
|
414 |
+
with gr.Row(visible=False) as custom_size:
|
415 |
+
custom_size_height = gr.Number(
|
416 |
+
value=413, label="height", interactive=True
|
417 |
+
)
|
418 |
+
custom_size_wdith = gr.Number(
|
419 |
+
value=295, label="width", interactive=True
|
420 |
+
)
|
421 |
|
422 |
+
# 左:背景色选项
|
423 |
+
color_options = gr.Radio(
|
424 |
+
choices=colors_CN, label="背景色", value="蓝色", elem_id="color"
|
425 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
|
427 |
+
# 左:如果选择「自定义底色」,显示 RGB 输入框
|
428 |
+
with gr.Row(visible=False) as custom_color:
|
429 |
+
custom_color_R = gr.Number(value=0, label="R", interactive=True)
|
430 |
+
custom_color_G = gr.Number(value=0, label="G", interactive=True)
|
431 |
+
custom_color_B = gr.Number(value=0, label="B", interactive=True)
|
432 |
+
|
433 |
+
# 左:渲染方式选项
|
434 |
+
render_options = gr.Radio(
|
435 |
+
choices=render_CN,
|
436 |
+
label="渲染方式",
|
437 |
+
value="纯色",
|
438 |
+
elem_id="render",
|
439 |
+
)
|
440 |
|
441 |
+
with gr.Tab("高级参数") as advance_parameter_tab:
|
442 |
+
# 面部占照片总比例
|
443 |
+
head_measure_ratio_option = gr.Slider(
|
444 |
+
minimum=0.1,
|
445 |
+
maximum=0.5,
|
446 |
+
value=0.2,
|
447 |
+
step=0.02,
|
448 |
+
label="面部比例",
|
449 |
interactive=True,
|
450 |
)
|
451 |
+
# 人像头顶距离照片顶部的比例
|
452 |
+
top_distance_option = gr.Slider(
|
453 |
+
minimum=0.02,
|
454 |
+
maximum=0.5,
|
455 |
+
value=0.12,
|
456 |
+
step=0.02,
|
457 |
+
label="头距顶距离",
|
458 |
+
interactive=True,
|
459 |
+
)
|
460 |
+
|
461 |
+
# 输出照片的KB值
|
462 |
+
image_kb_options = gr.Radio(
|
463 |
+
choices=image_kb_CN,
|
464 |
+
label="设置 KB 大小(结果在右边最底的组件下载)",
|
465 |
+
value="不设置",
|
466 |
+
elem_id="image_kb",
|
467 |
+
)
|
468 |
+
# 自定义 KB 大小,滑动条,最小 10KB,最大 200KB
|
469 |
+
with gr.Row(visible=False) as custom_image_kb:
|
470 |
+
custom_image_kb_size = gr.Slider(
|
471 |
+
minimum=10,
|
472 |
+
maximum=1000,
|
473 |
+
value=50,
|
474 |
+
label="KB 大小",
|
475 |
+
interactive=True,
|
476 |
+
)
|
477 |
|
478 |
img_but = gr.Button("开始制作")
|
479 |
|
|
|
544 |
img_output_standard_hd: gr.update(label="高清照"),
|
545 |
img_output_layout: gr.update(label="六寸排版照"),
|
546 |
file_download: gr.update(label="下载调整 KB 大小后的照片"),
|
547 |
+
head_measure_ratio_option: gr.update(label="面部比例"),
|
548 |
+
top_distance_option: gr.update(label="头距顶距离"),
|
549 |
+
key_parameter_tab: gr.update(label="核心参数"),
|
550 |
+
advance_parameter_tab: gr.update(label="高级参数"),
|
551 |
}
|
552 |
|
553 |
elif language == "English":
|
|
|
588 |
file_download: gr.update(
|
589 |
label="Download the photo after adjusting the KB size"
|
590 |
),
|
591 |
+
head_measure_ratio_option: gr.update(label="Head ratio"),
|
592 |
+
top_distance_option: gr.update(label="Top distance"),
|
593 |
+
key_parameter_tab: gr.update(label="Key Parameters"),
|
594 |
+
advance_parameter_tab: gr.update(label="Advance Parameters"),
|
595 |
}
|
596 |
|
597 |
def change_color(colors):
|
|
|
648 |
img_output_standard_hd,
|
649 |
img_output_layout,
|
650 |
file_download,
|
651 |
+
head_measure_ratio_option,
|
652 |
+
top_distance_option,
|
653 |
+
key_parameter_tab,
|
654 |
+
advance_parameter_tab,
|
655 |
],
|
656 |
)
|
657 |
|
|
|
687 |
language_options,
|
688 |
matting_model_options,
|
689 |
face_detect_model_options,
|
690 |
+
head_measure_ratio_option,
|
691 |
+
top_distance_option,
|
692 |
],
|
693 |
outputs=[
|
694 |
img_output_standard,
|