Spaces:
Running
Running
TheEeeeLin
commited on
Commit
•
2bd7a14
1
Parent(s):
ec5a4d3
update
Browse files- demo/assets/title.md +1 -2
- demo/locales.py +34 -2
- demo/processor.py +28 -13
- demo/ui.py +24 -0
demo/assets/title.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
|
2 |
<div style="display: flex; align-items: center;">
|
3 |
<img src="https://swanhub.co/git/repo/ZeYiLin%2FHivisionIDPhotos/file/preview?ref=master&path=assets/hivision_logo.png" alt="HivisionIDPhotos" style="width: 65px; height: 65px; margin-right: 10px;" onerror="this.style.display='none';" loading="lazy">
|
4 |
-
<b style="color: #6e9abb;">HivisionIDPhotos</b><span style="font-size: 18px; color: #638fb3; margin-left: 10px;"> v1.
|
5 |
</div>
|
6 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
7 |
<a href="https://github.com/xiaolin199912/HivisionIDPhotos"><img alt="Github" src="https://img.shields.io/static/v1?label=GitHub&message=GitHub&color=black" onerror="this.style.display='none';"></a>  
|
8 |
-
<a href="https://docs.qq.com/doc/DUkpBdk90eWZFS2JW" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/WeChat-微信-4cb55e" onerror="this.style.display='none';"></a>  
|
9 |
<a href="https://github.com/xiaolin199912/HivisionIDPhotos/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/zeyi-lin/hivisionidphotos?color=ffcb47&labelColor=black&style=flat-square" onerror="this.style.display='none';"></a>  
|
10 |
<a href="https://swanlab.cn?utm_source=hivision_demo"><img alt="SwanLab" src="https://img.shields.io/badge/Training%20by-SwanLab-4cb55e" onerror="this.style.display='none';"></a>  
|
11 |
<a href="https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_CN.md" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/API_Docs-API文档-315bce" onerror="this.style.display='none';"></a>
|
|
|
1 |
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
|
2 |
<div style="display: flex; align-items: center;">
|
3 |
<img src="https://swanhub.co/git/repo/ZeYiLin%2FHivisionIDPhotos/file/preview?ref=master&path=assets/hivision_logo.png" alt="HivisionIDPhotos" style="width: 65px; height: 65px; margin-right: 10px;" onerror="this.style.display='none';" loading="lazy">
|
4 |
+
<b style="color: #6e9abb;">HivisionIDPhotos</b><span style="font-size: 18px; color: #638fb3; margin-left: 10px;"> v1.3.1</span>
|
5 |
</div>
|
6 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
7 |
<a href="https://github.com/xiaolin199912/HivisionIDPhotos"><img alt="Github" src="https://img.shields.io/static/v1?label=GitHub&message=GitHub&color=black" onerror="this.style.display='none';"></a>  
|
|
|
8 |
<a href="https://github.com/xiaolin199912/HivisionIDPhotos/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/zeyi-lin/hivisionidphotos?color=ffcb47&labelColor=black&style=flat-square" onerror="this.style.display='none';"></a>  
|
9 |
<a href="https://swanlab.cn?utm_source=hivision_demo"><img alt="SwanLab" src="https://img.shields.io/badge/Training%20by-SwanLab-4cb55e" onerror="this.style.display='none';"></a>  
|
10 |
<a href="https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_CN.md" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/API_Docs-API文档-315bce" onerror="this.style.display='none';"></a>
|
demo/locales.py
CHANGED
@@ -675,12 +675,12 @@ LOCALES = {
|
|
675 |
},
|
676 |
"zh": {
|
677 |
"label": "🤖插件",
|
678 |
-
"choices": ["人脸旋转对齐", "排版照裁剪线", "JPEG格式"
|
679 |
"value": ["排版照裁剪线"]
|
680 |
},
|
681 |
"ja": {
|
682 |
"label": "🤖プラグイン",
|
683 |
-
"choices": ["顔の整列", "レイアウト写真の切り取り線", "JPEGフォーマット"
|
684 |
"value": ["レイアウト写真の切り取り線"]
|
685 |
},
|
686 |
"ko": {
|
@@ -703,4 +703,36 @@ LOCALES = {
|
|
703 |
"label": "SNS 템플릿 사진",
|
704 |
},
|
705 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
706 |
}
|
|
|
675 |
},
|
676 |
"zh": {
|
677 |
"label": "🤖插件",
|
678 |
+
"choices": ["人脸旋转对齐", "排版照裁剪线", "JPEG格式"],
|
679 |
"value": ["排版照裁剪线"]
|
680 |
},
|
681 |
"ja": {
|
682 |
"label": "🤖プラグイン",
|
683 |
+
"choices": ["顔の整列", "レイアウト写真の切り取り線", "JPEGフォーマット"],
|
684 |
"value": ["レイアウト写真の切り取り線"]
|
685 |
},
|
686 |
"ko": {
|
|
|
703 |
"label": "SNS 템플릿 사진",
|
704 |
},
|
705 |
},
|
706 |
+
"print_tab": {
|
707 |
+
"en": {
|
708 |
+
"label": "Print Layout",
|
709 |
+
},
|
710 |
+
"zh": {
|
711 |
+
"label": "打印排版",
|
712 |
+
},
|
713 |
+
"ja": {
|
714 |
+
"label": "印刷レイアウト",
|
715 |
+
},
|
716 |
+
"ko": {
|
717 |
+
"label": "인쇄 레이아웃",
|
718 |
+
},
|
719 |
+
},
|
720 |
+
"print_switch": {
|
721 |
+
"en": {
|
722 |
+
"label": "Paper size",
|
723 |
+
"choices": ["6 inch", "5 inch", "A4", "3R", "4R"],
|
724 |
+
},
|
725 |
+
"zh": {
|
726 |
+
"label": "相纸选择",
|
727 |
+
"choices": ["六寸", "五寸", "A4", "3R", "4R"],
|
728 |
+
},
|
729 |
+
"ja": {
|
730 |
+
"label": "用紙サイズ",
|
731 |
+
"choices": ["6インチ", "5インチ", "A4", "3R", "4R"],
|
732 |
+
},
|
733 |
+
"ko": {
|
734 |
+
"label": "용지 사이즈",
|
735 |
+
"choices": ["6인치", "5인치", "A4", "3R", "4R"],
|
736 |
+
},
|
737 |
+
},
|
738 |
}
|
demo/processor.py
CHANGED
@@ -62,6 +62,7 @@ class IDPhotoProcessor:
|
|
62 |
sharpen_strength=0,
|
63 |
saturation_strength=0,
|
64 |
plugin_option=[],
|
|
|
65 |
):
|
66 |
# 初始化参数
|
67 |
top_distance_min = top_distance_max - 0.02
|
@@ -85,14 +86,9 @@ class IDPhotoProcessor:
|
|
85 |
jpeg_format_option = True
|
86 |
else:
|
87 |
jpeg_format_option = False
|
88 |
-
# 五寸相纸选项
|
89 |
-
if LOCALES["plugin"][language]["choices"][3] in plugin_option:
|
90 |
-
five_inch_option = True
|
91 |
-
else:
|
92 |
-
five_inch_option = False
|
93 |
|
94 |
idphoto_json = self._initialize_idphoto_json(
|
95 |
-
mode_option, color_option, render_option_index, image_kb_options, layout_photo_crop_line_option, jpeg_format_option,
|
96 |
)
|
97 |
|
98 |
# 处理尺寸模式
|
@@ -177,7 +173,7 @@ class IDPhotoProcessor:
|
|
177 |
image_kb_options,
|
178 |
layout_photo_crop_line_option,
|
179 |
jpeg_format_option,
|
180 |
-
|
181 |
):
|
182 |
"""初始化idphoto_json字典"""
|
183 |
return {
|
@@ -189,7 +185,7 @@ class IDPhotoProcessor:
|
|
189 |
"custom_image_dpi": None,
|
190 |
"layout_photo_crop_line_option": layout_photo_crop_line_option,
|
191 |
"jpeg_format_option": jpeg_format_option,
|
192 |
-
"
|
193 |
}
|
194 |
|
195 |
# 处理尺寸模式
|
@@ -320,10 +316,11 @@ class IDPhotoProcessor:
|
|
320 |
"""处理照片生成错误"""
|
321 |
return [gr.update(value=None) for _ in range(4)] + [
|
322 |
gr.update(visible=False),
|
|
|
|
|
323 |
gr.update(
|
324 |
value=LOCALES["notification"][language]["face_error"], visible=True
|
325 |
),
|
326 |
-
None,
|
327 |
]
|
328 |
|
329 |
# 处理生成的照片
|
@@ -445,11 +442,29 @@ class IDPhotoProcessor:
|
|
445 |
if idphoto_json["size_mode"] in LOCALES["size_mode"][language]["choices"][1]:
|
446 |
return None, False
|
447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
typography_arr, typography_rotate = generate_layout_array(
|
449 |
input_height=idphoto_json["size"][0],
|
450 |
input_width=idphoto_json["size"][1],
|
451 |
-
LAYOUT_HEIGHT=
|
452 |
-
LAYOUT_WIDTH=
|
453 |
)
|
454 |
|
455 |
result_image_layout = generate_layout_image(
|
@@ -459,8 +474,8 @@ class IDPhotoProcessor:
|
|
459 |
height=idphoto_json["size"][0],
|
460 |
width=idphoto_json["size"][1],
|
461 |
crop_line=idphoto_json["layout_photo_crop_line_option"],
|
462 |
-
LAYOUT_HEIGHT=
|
463 |
-
LAYOUT_WIDTH=
|
464 |
)
|
465 |
|
466 |
return result_image_layout, True
|
|
|
62 |
sharpen_strength=0,
|
63 |
saturation_strength=0,
|
64 |
plugin_option=[],
|
65 |
+
print_switch=None,
|
66 |
):
|
67 |
# 初始化参数
|
68 |
top_distance_min = top_distance_max - 0.02
|
|
|
86 |
jpeg_format_option = True
|
87 |
else:
|
88 |
jpeg_format_option = False
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
idphoto_json = self._initialize_idphoto_json(
|
91 |
+
mode_option, color_option, render_option_index, image_kb_options, layout_photo_crop_line_option, jpeg_format_option, print_switch
|
92 |
)
|
93 |
|
94 |
# 处理尺寸模式
|
|
|
173 |
image_kb_options,
|
174 |
layout_photo_crop_line_option,
|
175 |
jpeg_format_option,
|
176 |
+
print_switch,
|
177 |
):
|
178 |
"""初始化idphoto_json字典"""
|
179 |
return {
|
|
|
185 |
"custom_image_dpi": None,
|
186 |
"layout_photo_crop_line_option": layout_photo_crop_line_option,
|
187 |
"jpeg_format_option": jpeg_format_option,
|
188 |
+
"print_switch": print_switch,
|
189 |
}
|
190 |
|
191 |
# 处理尺寸模式
|
|
|
316 |
"""处理照片生成错误"""
|
317 |
return [gr.update(value=None) for _ in range(4)] + [
|
318 |
gr.update(visible=False),
|
319 |
+
gr.update(value=None),
|
320 |
+
gr.update(value=None),
|
321 |
gr.update(
|
322 |
value=LOCALES["notification"][language]["face_error"], visible=True
|
323 |
),
|
|
|
324 |
]
|
325 |
|
326 |
# 处理生成的照片
|
|
|
442 |
if idphoto_json["size_mode"] in LOCALES["size_mode"][language]["choices"][1]:
|
443 |
return None, False
|
444 |
|
445 |
+
# 预设排版照尺寸
|
446 |
+
SIX_INCH = [1205, 1795]
|
447 |
+
FIVE_INCH = [1051, 1500]
|
448 |
+
A4 = [2479, 3508]
|
449 |
+
THREE_R = [1051, 1500]
|
450 |
+
FOUR_R = [1205, 1795]
|
451 |
+
|
452 |
+
# 预设排版照尺寸字典
|
453 |
+
PRESET_LAYOUT_SIZE = {
|
454 |
+
LOCALES["print_switch"][language]["choices"][0]: SIX_INCH,
|
455 |
+
LOCALES["print_switch"][language]["choices"][1]: FIVE_INCH,
|
456 |
+
LOCALES["print_switch"][language]["choices"][2]: A4,
|
457 |
+
LOCALES["print_switch"][language]["choices"][3]: THREE_R,
|
458 |
+
LOCALES["print_switch"][language]["choices"][4]: FOUR_R,
|
459 |
+
}
|
460 |
+
|
461 |
+
choose_layout_size = PRESET_LAYOUT_SIZE[idphoto_json["print_switch"]]
|
462 |
+
|
463 |
typography_arr, typography_rotate = generate_layout_array(
|
464 |
input_height=idphoto_json["size"][0],
|
465 |
input_width=idphoto_json["size"][1],
|
466 |
+
LAYOUT_HEIGHT= choose_layout_size[0],
|
467 |
+
LAYOUT_WIDTH= choose_layout_size[1],
|
468 |
)
|
469 |
|
470 |
result_image_layout = generate_layout_image(
|
|
|
474 |
height=idphoto_json["size"][0],
|
475 |
width=idphoto_json["size"][1],
|
476 |
crop_line=idphoto_json["layout_photo_crop_line_option"],
|
477 |
+
LAYOUT_HEIGHT=choose_layout_size[0],
|
478 |
+
LAYOUT_WIDTH=choose_layout_size[1],
|
479 |
)
|
480 |
|
481 |
return result_image_layout, True
|
demo/ui.py
CHANGED
@@ -340,6 +340,19 @@ def create_ui(
|
|
340 |
watermark_text_space,
|
341 |
],
|
342 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
|
344 |
img_but = gr.Button(
|
345 |
LOCALES["button"][DEFAULT_LANG]["label"],
|
@@ -557,6 +570,14 @@ def create_ui(
|
|
557 |
choices=LOCALES["plugin"][language]["choices"],
|
558 |
value=LOCALES["plugin"][language]["choices"][0],
|
559 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
}
|
561 |
|
562 |
def change_visibility(option, lang, locales_key, custom_component):
|
@@ -667,6 +688,8 @@ def create_ui(
|
|
667 |
custom_size_height_mm,
|
668 |
img_output_template,
|
669 |
template_image_accordion,
|
|
|
|
|
670 |
],
|
671 |
)
|
672 |
|
@@ -742,6 +765,7 @@ def create_ui(
|
|
742 |
sharpen_option,
|
743 |
saturation_option,
|
744 |
plugin_options,
|
|
|
745 |
],
|
746 |
outputs=[
|
747 |
img_output_standard,
|
|
|
340 |
watermark_text_space,
|
341 |
],
|
342 |
)
|
343 |
+
|
344 |
+
# TAB5 - 打印 ------------------------------------------------
|
345 |
+
with gr.Tab(
|
346 |
+
LOCALES["print_tab"][DEFAULT_LANG]["label"]
|
347 |
+
) as print_parameter_tab:
|
348 |
+
print_options = gr.Radio(
|
349 |
+
choices=LOCALES["print_switch"][DEFAULT_LANG]["choices"],
|
350 |
+
label=LOCALES["print_switch"][DEFAULT_LANG]["label"],
|
351 |
+
value=LOCALES["print_switch"][DEFAULT_LANG]["choices"][0],
|
352 |
+
interactive=True,
|
353 |
+
)
|
354 |
+
|
355 |
+
|
356 |
|
357 |
img_but = gr.Button(
|
358 |
LOCALES["button"][DEFAULT_LANG]["label"],
|
|
|
570 |
choices=LOCALES["plugin"][language]["choices"],
|
571 |
value=LOCALES["plugin"][language]["choices"][0],
|
572 |
),
|
573 |
+
print_parameter_tab: gr.update(
|
574 |
+
label=LOCALES["print_tab"][language]["label"]
|
575 |
+
),
|
576 |
+
print_options: gr.update(
|
577 |
+
label=LOCALES["print_switch"][language]["label"],
|
578 |
+
choices=LOCALES["print_switch"][language]["choices"],
|
579 |
+
value=LOCALES["print_switch"][language]["choices"][0],
|
580 |
+
),
|
581 |
}
|
582 |
|
583 |
def change_visibility(option, lang, locales_key, custom_component):
|
|
|
688 |
custom_size_height_mm,
|
689 |
img_output_template,
|
690 |
template_image_accordion,
|
691 |
+
print_parameter_tab,
|
692 |
+
print_options,
|
693 |
],
|
694 |
)
|
695 |
|
|
|
765 |
sharpen_option,
|
766 |
saturation_option,
|
767 |
plugin_options,
|
768 |
+
print_options,
|
769 |
],
|
770 |
outputs=[
|
771 |
img_output_standard,
|