Skip to content

Commit

Permalink
feat: gradio png download and api docs jp ko (#96)
Browse files Browse the repository at this point in the history
* add light gray

* init

* add gr image png

* Update title.md
  • Loading branch information
Zeyi-Lin authored Sep 10, 2024
1 parent a4bb4ce commit a956814
Show file tree
Hide file tree
Showing 11 changed files with 1,073 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
demo.launch(
server_name=args.host,
server_port=args.port,
show_api=False,
favicon_path=os.path.join(root_dir, "assets/hivision_logo.png"),
root_path=args.root_path,
show_api=False,
)
17 changes: 8 additions & 9 deletions assets/title.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
<div>
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
<div style="display: flex; align-items: center;">
<b>HivisionIDPhotos</b>
<br>
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
<a href="https://github.com/xiaolin199912/HivisionIDPhotos"><img alt="Github" src="https://img.shields.io/static/v1?label=GitHub&message=GitHub&color=black"></a> &ensp;
<a href="https://docs.qq.com/doc/DUkpBdk90eWZFS2JW" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/WeChat-微信-4cb55e"></a> &ensp;
<a href="https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_EN.md" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/API_Docs-API文档-315bce"></a>
</div>
</div>
</div>
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
<a href="https://github.com/xiaolin199912/HivisionIDPhotos"><img alt="Github" src="https://img.shields.io/static/v1?label=GitHub&message=GitHub&color=black"></a> &ensp;
<a href="https://docs.qq.com/doc/DUkpBdk90eWZFS2JW" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/WeChat-微信-4cb55e"></a> &ensp;
<a href="https://github.com/Zeyi-Lin/HivisionIDPhotos/blob/master/docs/api_EN.md" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/API_Docs-API文档-315bce"></a>
</div>
</div>
3 changes: 2 additions & 1 deletion demo/assets/color_list_CN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Name,Hex
白色,ffffff
红色,d74532
黑色,000000
深蓝色,4b6190
深蓝色,4b6190
浅灰色,f2f0f0
3 changes: 2 additions & 1 deletion demo/assets/color_list_EN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Blue,628bce
White,ffffff
Red,d74532
Black,000000
Dark Blue,4b6190
Dark Blue,4b6190
Light Gray,f2f0f0
8 changes: 8 additions & 0 deletions demo/locals.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@
"label": "高清照",
},
},
"hd_photo_png": {
"en": {
"label": "Matting photo",
},
"zh": {
"label": "透明图",
},
},
"layout_photo": {
"en": {
"label": "Layout photo",
Expand Down
4 changes: 4 additions & 0 deletions demo/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def process(
return [
gr.update(value=None), # img_output_standard
gr.update(value=None), # img_output_standard_hd
gr.update(value=None), # img_output_standard_hd_png
gr.update(visible=False), # img_output_layout
gr.update( # notification
value=LOCALES["notification"][language]["face_error"],
Expand All @@ -147,6 +148,7 @@ def process(

else:
(result_image_standard, result_image_hd, _, _) = result
result_image_hd_png = np.uint8(result_image_hd)
if (
idphoto_json["render_mode"]
== LOCALES["render_mode"][language]["choices"][0]
Expand Down Expand Up @@ -272,6 +274,7 @@ def process(
return [
result_image_standard, # img_output_standard
result_image_hd, # img_output_standard_hd
result_image_hd_png, # img_output_standard_hd_png
result_layout_image, # img_output_layout
gr.update(visible=False), # notification
gr.update(visible=True, value=output_image_path), # file_download
Expand All @@ -280,6 +283,7 @@ def process(
return [
result_image_standard, # img_output_standard
result_image_hd, # img_output_standard_hd
result_image_hd_png, # img_output_standard_hd_png
result_layout_image, # img_output_layout
gr.update(visible=False), # notification
gr.update(visible=False), # file_download
Expand Down
40 changes: 16 additions & 24 deletions demo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,7 @@ def create_ui(
human_matting_models.remove(DEFAULT_HUMAN_MATTING_MODEL)
human_matting_models.insert(0, DEFAULT_HUMAN_MATTING_MODEL)

css = """
#col-left {
margin: 0 auto;
max-width: 430px;
}
#col-mid {
margin: 0 auto;
max-width: 430px;
}
#col-right {
margin: 0 auto;
max-width: 430px;
}
#col-showcase {
margin: 0 auto;
max-width: 1100px;
}
#button {
color: blue;
}
"""

demo = gr.Blocks(title="HivisionIDPhotos", css=css)
demo = gr.Blocks(title="HivisionIDPhotos")

with demo:
gr.HTML(load_description(os.path.join(root_dir, "assets/title.md")))
Expand Down Expand Up @@ -237,7 +215,9 @@ def update_watermark_text_visibility(choice, language):
],
)

img_but = gr.Button(LOCALES["button"][DEFAULT_LANG]["label"])
img_but = gr.Button(
LOCALES["button"][DEFAULT_LANG]["label"], elem_id="btn"
)

example_images = gr.Examples(
inputs=[img_input],
Expand Down Expand Up @@ -267,6 +247,13 @@ 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,
Expand Down Expand Up @@ -323,6 +310,9 @@ def change_language(language):
img_output_standard_hd: gr.update(
label=LOCALES["hd_photo"][language]["label"]
),
img_output_standard_hd_png: gr.update(
label=LOCALES["hd_photo_png"][language]["label"]
),
img_output_layout: gr.update(
label=LOCALES["layout_photo"][language]["label"]
),
Expand Down Expand Up @@ -422,6 +412,7 @@ def change_image_kb(image_kb_option):
notification,
img_output_standard,
img_output_standard_hd,
img_output_standard_hd_png,
img_output_layout,
file_download,
head_measure_ratio_option,
Expand Down Expand Up @@ -484,6 +475,7 @@ def change_image_kb(image_kb_option):
outputs=[
img_output_standard,
img_output_standard_hd,
img_output_standard_hd_png,
img_output_layout,
notification,
file_download,
Expand Down
3 changes: 2 additions & 1 deletion docs/api_CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# API Docs

中文 | [English](api_EN.md)
[English](api_EN.md) / 中文 / [日本語](api_JP.md) / [한국어](api_KO.md)


## 目录

Expand Down
3 changes: 2 additions & 1 deletion docs/api_EN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# API Docs

[中文](api_CN.md) | English
English / [中文](api_CN.md) / [日本語](api_JP.md) / [한국어](api_KO.md)


## Table of Contents

Expand Down
Loading

0 comments on commit a956814

Please sign in to comment.