diff --git a/README.md b/README.md index d3df1946..b08ac641 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ - 在线体验: [![SwanHub Demo](https://img.shields.io/static/v1?label=Demo&message=SwanHub%20Demo&color=blue)](https://swanhub.co/ZeYiLin/HivisionIDPhotos/demo)、[![Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue)](https://huggingface.co/spaces/TheEeeeLin/HivisionIDPhotos)、[![][modelscope-shield]][modelscope-link] -- 2024.09.16: Gradio Demo增加**人脸旋转对齐**功能 +- 2024.09.16: Gradio Demo增加**人脸旋转对齐**功能,自定义尺寸输入支持**毫米**单位 - 2024.09.14: Gradio Demo增加**自定义DPI**功能,增加日语和韩语支持,增加**调整亮度、对比度、锐度**功能 - 2024.09.12: Gradio Demo增加**美白**功能 | API接口增加**加水印**、**设置照片KB值大小**、**证件照裁切** - 2024.09.11: Gradio Demo增加**透明图显示与下载**功能 diff --git a/README_EN.md b/README_EN.md index 17d0ab4f..062f5f03 100644 --- a/README_EN.md +++ b/README_EN.md @@ -53,7 +53,7 @@ English / [中文](README.md) / [日本語](README_JP.md) / [한국어](README_K - Online Experience: [![SwanHub Demo](https://img.shields.io/static/v1?label=Demo&message=SwanHub%20Demo&color=blue)](https://swanhub.co/ZeYiLin/HivisionIDPhotos/demo)、[![Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue)](https://huggingface.co/spaces/TheEeeeLin/HivisionIDPhotos)、[![][modelscope-shield]][modelscope-link] -- 2024.09.16: Gradio Demo adds **Face Rotation Alignment** feature +- 2024.09.16: Gradio Demo adds **Face Rotation Alignment** feature, custom size input supports **millimeters** - 2024.09.14: Gradio Demo adds **Custom DPI** feature, adds Japanese and Korean support, adds **Adjust Brightness, Contrast, Sharpness** feature - 2024.09.12: Gradio Demo adds **Whitening** feature | API interface adds **Watermark**, **Set Photo KB Size**, **ID Photo Cropping** - 2024.09.11: Added **transparent image display and download** feature to Gradio Demo. diff --git a/README_JP.md b/README_JP.md index db6de493..82ca160d 100644 --- a/README_JP.md +++ b/README_JP.md @@ -51,7 +51,7 @@ - オンライン体験: [![SwanHub Demo](https://img.shields.io/static/v1?label=Demo&message=SwanHub%20Demo&color=blue)](https://swanhub.co/ZeYiLin/HivisionIDPhotos/demo)、[![Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue)](https://huggingface.co/spaces/TheEeeeLin/HivisionIDPhotos)、[![][modelscope-shield]][modelscope-link] -- 2024.09.16: Gradioデモに**顔回転対応**機能を追加 +- 2024.09.16: Gradioデモに**顔回転対応**機能を追加、カスタムサイズ入力に**ミリメートル**をサポート - 2024.09.14: Gradioデモに**カスタムDPI**機能を追加、日本語と韓国語を追加,**明るさ、コントラスト、鮮明度の調整**機能を追加 - 2024.09.12: Gradioデモに**ホワイトニング**機能を追加 | APIインターフェースに**ウォーターマーク追加**、**写真のKBサイズ設定**、**証明写真のトリミング**を追加 - 2024.09.11: Gradioデモに**透過画像表示とダウンロード**機能を追加しました。 diff --git a/README_KO.md b/README_KO.md index f978f978..229a0c1f 100644 --- a/README_KO.md +++ b/README_KO.md @@ -51,7 +51,7 @@ - 온라인 체험: [![SwanHub Demo](https://img.shields.io/static/v1?label=Demo&message=SwanHub%20Demo&color=blue)](https://swanhub.co/ZeYiLin/HivisionIDPhotos/demo)、[![Spaces](https://img.shields.io/badge/🤗-Open%20in%20Spaces-blue)](https://huggingface.co/spaces/TheEeeeLin/HivisionIDPhotos)、[![][modelscope-shield]][modelscope-link] -- 2024.09.16: Gradio Demo에 **얼굴 회전 정렬** 기능 추가 +- 2024.09.16: Gradio Demo에 **얼굴 회전 정렬** 기능 추가, 커스텀 사이즈 입력에 **밀리미터** 단위 추가 - 2024.09.14: Gradio Demo에 **커스텀 DPI** 기능 추가, 일본어와 한국어 추가, **밝기, 대비, 선명도 조절** 기능 추가 - 2024.09.12: Gradio 데모에 **미백** 기능 추가 | API 인터페이스에 **워터마크 추가**, **사진 KB 크기 설정**, **증명사진 자르기** 추가 - 2024.09.11: Gradio Demo에 **투명 이미지 표시 및 다운로드** 기능 추가 diff --git a/demo/locales.py b/demo/locales.py index fb6d0b2c..1bdab463 100644 --- a/demo/locales.py +++ b/demo/locales.py @@ -87,12 +87,17 @@ "size_mode": { "en": { "label": "ID photo size options", - "choices": ["Size List", "Only Change Background", "Custom Size"], + "choices": [ + "Size List", + "Only Change BG", + "Custom(px)", + "Custom(mm)", + ], "custom_size_eror": "The width should not be greater than the length; the length and width should not be less than 100, and no more than 1800.", }, "zh": { "label": "证件照尺寸选项", - "choices": ["尺寸列表", "只换底", "自定义尺寸"], + "choices": ["尺寸列表", "只换底", "自定义(px)", "自定义(mm)"], "custom_size_eror": "宽度不应大于长度;长度和宽度不应小于100,不大于1800。", }, "ja": { @@ -100,16 +105,58 @@ "choices": [ "サイズリスト", "背景のみ変更", - "カスタムサイズ", + "カスタムサイズ(px)", + "カスタムサイズ(mm)", ], "custom_size_eror": "幅は長さより大きくしないでください。長さと幅は100以上1800以下にしてください。", }, "ko": { "label": "증명사진 크기 옵션", - "choices": ["크기 목록", "배경만 변경", "사용자 지정 크기"], + "choices": [ + "크기 목록", + "배경만 변경", + "사용자 지정(px)", + "사용자 지정(mm)", + ], "custom_size_eror": "너비는 길이보다 크지 않아야 합니다; 길이와 너비는 100 이상 1800 이하여야 합니다.", }, }, + "custom_size_px": { + "en": { + "height": "Height(px)", + "width": "Width(px)", + }, + "zh": { + "height": "高度(px)", + "width": "宽度(px)", + }, + "ja": { + "height": "高さ(px)", + "width": "幅(px)", + }, + "ko": { + "height": "높이(px)", + "width": "너비(px)", + }, + }, + "custom_size_mm": { + "en": { + "height": "Height(mm)", + "width": "Width(mm)", + }, + "zh": { + "height": "高度(mm)", + "width": "宽度(mm)", + }, + "ja": { + "height": "高さ(mm)", + "width": "幅(mm)", + }, + "ko": { + "height": "높이(mm)", + "width": "너비(mm)", + }, + }, "size_list": { "en": { "label": "Size list", diff --git a/demo/processor.py b/demo/processor.py index 91d54029..7b6cf022 100644 --- a/demo/processor.py +++ b/demo/processor.py @@ -33,6 +33,8 @@ def process( custom_color_B, custom_size_height, custom_size_width, + custom_size_height_mm, + custom_size_width_mm, custom_image_kb, language, matting_model_option, @@ -72,6 +74,8 @@ def process( size_list_option, custom_size_height, custom_size_width, + custom_size_height_mm, + custom_size_width_mm, ) if isinstance(size_result, list): return size_result # 返回错误信息 @@ -159,14 +163,32 @@ def _process_size_mode( size_list_option, custom_size_height, custom_size_width, + custom_size_height_mm, + custom_size_width_mm, ): """处理尺寸模式""" + # 如果选择了尺寸列表 if idphoto_json["size_mode"] == LOCALES["size_mode"][language]["choices"][0]: idphoto_json["size"] = LOCALES["size_list"][language]["develop"][ size_list_option ] - elif idphoto_json["size_mode"] == LOCALES["size_mode"][language]["choices"][2]: - id_height, id_width = int(custom_size_height), int(custom_size_width) + # 如果选择了自定义尺寸(px或mm) + elif ( + idphoto_json["size_mode"] == LOCALES["size_mode"][language]["choices"][2] + or idphoto_json["size_mode"] == LOCALES["size_mode"][language]["choices"][3] + ): + # 如果选择了自定义尺寸(px) + if ( + idphoto_json["size_mode"] + == LOCALES["size_mode"][language]["choices"][2] + ): + id_height, id_width = int(custom_size_height), int(custom_size_width) + # 如果选择了自定义尺寸(mm) + else: + # 将mm转换为px + id_height = int(custom_size_height_mm / 25.4 * 300) + id_width = int(custom_size_width_mm / 25.4 * 300) + # 检查尺寸像素是否在100到1800之间 if ( id_height < id_width or min(id_height, id_width) < 100 @@ -174,6 +196,7 @@ def _process_size_mode( ): return self._create_error_response(language) idphoto_json["size"] = (id_height, id_width) + # 如果选择了只换底 else: idphoto_json["size"] = (None, None) diff --git a/demo/ui.py b/demo/ui.py index 713c35bb..540b5795 100644 --- a/demo/ui.py +++ b/demo/ui.py @@ -78,7 +78,7 @@ def create_ui( choices=LOCALES["size_mode"][DEFAULT_LANG]["choices"], label=LOCALES["size_mode"][DEFAULT_LANG]["label"], value=LOCALES["size_mode"][DEFAULT_LANG]["choices"][0], - min_width=500, + min_width=520, ) face_alignment_options = gr.CheckboxGroup( label=LOCALES["face_alignment"][DEFAULT_LANG]["label"], @@ -92,12 +92,27 @@ def create_ui( value=LOCALES["size_list"][DEFAULT_LANG]["choices"][0], elem_id="size_list", ) - with gr.Row(visible=False) as custom_size: - custom_size_height = gr.Number( - value=413, label="height", interactive=True + with gr.Row(visible=False) as custom_size_px: + custom_size_height_px = gr.Number( + value=413, + label=LOCALES["custom_size_px"][DEFAULT_LANG]["height"], + interactive=True, + ) + custom_size_width_px = gr.Number( + value=295, + label=LOCALES["custom_size_px"][DEFAULT_LANG]["width"], + interactive=True, ) - custom_size_width = gr.Number( - value=295, label="width", interactive=True + with gr.Row(visible=False) as custom_size_mm: + custom_size_height_mm = gr.Number( + value=35, + label=LOCALES["custom_size_mm"][DEFAULT_LANG]["height"], + interactive=True, + ) + custom_size_width_mm = gr.Number( + value=25, + label=LOCALES["custom_size_mm"][DEFAULT_LANG]["width"], + interactive=True, ) color_options = gr.Radio( @@ -498,6 +513,18 @@ def change_language(language): label=LOCALES["face_alignment"][language]["label"], choices=LOCALES["face_alignment"][language]["choices"], ), + custom_size_width_px: gr.update( + label=LOCALES["custom_size_px"][language]["width"] + ), + custom_size_height_px: gr.update( + label=LOCALES["custom_size_px"][language]["height"] + ), + custom_size_width_mm: gr.update( + label=LOCALES["custom_size_mm"][language]["width"] + ), + custom_size_height_mm: gr.update( + label=LOCALES["custom_size_mm"][language]["height"] + ), } def change_visibility(option, lang, locales_key, custom_component): @@ -512,24 +539,35 @@ def change_color(colors, lang): def change_size_mode(size_option_item, lang): choices = LOCALES["size_mode"][lang]["choices"] - # 如果选择自定义尺寸,则隐藏预设尺寸列表 - if size_option_item == choices[2]: + # 如果选择自定义尺寸mm + if size_option_item == choices[3]: + return { + custom_size_px: gr.update(visible=False), + custom_size_mm: gr.update(visible=True), + size_list_row: gr.update(visible=False), + face_alignment_options: gr.update(visible=True), + } + # 如果选择自定义尺寸px + elif size_option_item == choices[2]: return { - custom_size: gr.update(visible=True), + custom_size_px: gr.update(visible=True), + custom_size_mm: gr.update(visible=False), size_list_row: gr.update(visible=False), face_alignment_options: gr.update(visible=True), } # 如果选择只换底,则隐藏所有尺寸组件 elif size_option_item == choices[1]: return { - custom_size: gr.update(visible=False), + custom_size_px: gr.update(visible=False), + custom_size_mm: gr.update(visible=False), size_list_row: gr.update(visible=False), face_alignment_options: gr.update(visible=False), } # 如果选择预设尺寸,则隐藏自定义尺寸组件 else: return { - custom_size: gr.update(visible=False), + custom_size_px: gr.update(visible=False), + custom_size_mm: gr.update(visible=False), size_list_row: gr.update(visible=True), face_alignment_options: gr.update(visible=True), } @@ -588,27 +626,41 @@ def change_image_dpi(image_dpi_option, lang): sharpen_option, saturation_option, face_alignment_options, + custom_size_width_px, + custom_size_height_px, + custom_size_width_mm, + custom_size_height_mm, ], ) + # ---------------- 设置隐藏/显示交互效果 ---------------- + # 尺寸模式 + mode_options.input( + change_size_mode, + inputs=[mode_options, language_options], + outputs=[ + custom_size_px, + custom_size_mm, + size_list_row, + face_alignment_options, + ], + ) + + # 颜色 color_options.input( change_color, inputs=[color_options, language_options], outputs=[custom_color], ) - mode_options.input( - change_size_mode, - inputs=[mode_options, language_options], - outputs=[custom_size, size_list_row, face_alignment_options], - ) - + # 图片kb image_kb_options.input( change_image_kb, inputs=[image_kb_options, language_options], outputs=[custom_image_kb_size], ) + # 图片dpi image_dpi_options.input( change_image_dpi, inputs=[image_dpi_options, language_options], @@ -627,8 +679,10 @@ def change_image_dpi(image_dpi_option, lang): custom_color_R, custom_color_G, custom_color_B, - custom_size_height, - custom_size_width, + custom_size_height_px, + custom_size_width_px, + custom_size_height_mm, + custom_size_width_mm, custom_image_kb_size, language_options, matting_model_options,