Spaces:
Running
Running
TheEeeeLin
commited on
Commit
•
59bff44
1
Parent(s):
101deab
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,10 @@ from hivision.creator.layout_calculator import (
|
|
7 |
generate_layout_photo,
|
8 |
generate_layout_image,
|
9 |
)
|
|
|
|
|
|
|
|
|
10 |
import pathlib
|
11 |
import numpy as np
|
12 |
from demo.utils import csv_to_size_list
|
@@ -54,6 +58,7 @@ def idphoto_inference(
|
|
54 |
custom_size_width,
|
55 |
custom_image_kb,
|
56 |
language,
|
|
|
57 |
head_measure_ratio=0.2,
|
58 |
head_height_ratio=0.45,
|
59 |
top_distance_max=0.12,
|
@@ -146,6 +151,11 @@ def idphoto_inference(
|
|
146 |
idphoto_json["custom_image_kb"] = None
|
147 |
|
148 |
creator = IDCreator()
|
|
|
|
|
|
|
|
|
|
|
149 |
change_bg_only = idphoto_json["size_mode"] in ["只换底", "Only Change Background"]
|
150 |
# 生成证件照
|
151 |
try:
|
@@ -267,7 +277,24 @@ def idphoto_inference(
|
|
267 |
|
268 |
|
269 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
language = ["中文", "English"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
size_mode_CN = ["尺寸列表", "只换底", "自定义尺寸"]
|
272 |
size_mode_EN = ["Size List", "Only Change Background", "Custom Size"]
|
273 |
|
@@ -283,14 +310,6 @@ if __name__ == "__main__":
|
|
283 |
image_kb_CN = ["不设置", "自定义"]
|
284 |
image_kb_EN = ["Not Set", "Custom"]
|
285 |
|
286 |
-
# title = "<h1 id='title'>HivisionIDPhotos</h1>"
|
287 |
-
# description = "<h3>😎9.2 Update: Add photo size KB adjustment</h3>"
|
288 |
-
# css = """
|
289 |
-
# h1#title, h3 {
|
290 |
-
# text-align: center;
|
291 |
-
# }
|
292 |
-
# """
|
293 |
-
|
294 |
css = """
|
295 |
#col-left {
|
296 |
margin: 0 auto;
|
@@ -326,9 +345,20 @@ if __name__ == "__main__":
|
|
326 |
# ------------ 左半边 UI ----------------
|
327 |
with gr.Column():
|
328 |
img_input = gr.Image(height=400)
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
mode_options = gr.Radio(
|
334 |
choices=size_mode_CN,
|
@@ -453,6 +483,7 @@ if __name__ == "__main__":
|
|
453 |
img_output_layout: gr.update(label="六寸排版照"),
|
454 |
file_download: gr.update(label="下载调整 KB 大小后的照片"),
|
455 |
}
|
|
|
456 |
elif language == "English":
|
457 |
return {
|
458 |
size_list_options: gr.update(
|
@@ -576,6 +607,7 @@ if __name__ == "__main__":
|
|
576 |
custom_size_wdith,
|
577 |
custom_image_kb_size,
|
578 |
language_options,
|
|
|
579 |
],
|
580 |
outputs=[
|
581 |
img_output_standard,
|
@@ -586,13 +618,4 @@ if __name__ == "__main__":
|
|
586 |
],
|
587 |
)
|
588 |
|
589 |
-
|
590 |
-
# argparser.add_argument(
|
591 |
-
# "--port", type=int, default=7860, help="The port number of the server"
|
592 |
-
# )
|
593 |
-
# argparser.add_argument(
|
594 |
-
# "--host", type=str, default="127.0.0.1", help="The host of the server"
|
595 |
-
# )
|
596 |
-
# args = argparser.parse_args()
|
597 |
-
|
598 |
-
demo.launch()
|
|
|
7 |
generate_layout_photo,
|
8 |
generate_layout_image,
|
9 |
)
|
10 |
+
from hivision.creator.human_matting import (
|
11 |
+
extract_human_modnet_photographic_portrait_matting,
|
12 |
+
extract_human,
|
13 |
+
)
|
14 |
import pathlib
|
15 |
import numpy as np
|
16 |
from demo.utils import csv_to_size_list
|
|
|
58 |
custom_size_width,
|
59 |
custom_image_kb,
|
60 |
language,
|
61 |
+
matting_model_option,
|
62 |
head_measure_ratio=0.2,
|
63 |
head_height_ratio=0.45,
|
64 |
top_distance_max=0.12,
|
|
|
151 |
idphoto_json["custom_image_kb"] = None
|
152 |
|
153 |
creator = IDCreator()
|
154 |
+
if matting_model_option == "modnet_photographic_portrait_matting":
|
155 |
+
creator.matting_handler = extract_human_modnet_photographic_portrait_matting
|
156 |
+
else:
|
157 |
+
creator.matting_handler = extract_human
|
158 |
+
|
159 |
change_bg_only = idphoto_json["size_mode"] in ["只换底", "Only Change Background"]
|
160 |
# 生成证件照
|
161 |
try:
|
|
|
277 |
|
278 |
|
279 |
if __name__ == "__main__":
|
280 |
+
# argparser = argparse.ArgumentParser()
|
281 |
+
# argparser.add_argument(
|
282 |
+
# "--port", type=int, default=7860, help="The port number of the server"
|
283 |
+
# )
|
284 |
+
# argparser.add_argument(
|
285 |
+
# "--host", type=str, default="127.0.0.1", help="The host of the server"
|
286 |
+
# )
|
287 |
+
|
288 |
+
# args = argparser.parse_args()
|
289 |
+
|
290 |
language = ["中文", "English"]
|
291 |
+
|
292 |
+
matting_model_list = [
|
293 |
+
os.path.splitext(file)[0]
|
294 |
+
for file in os.listdir(os.path.join(root_dir, "hivision/creator/weights"))
|
295 |
+
if file.endswith(".onnx")
|
296 |
+
]
|
297 |
+
|
298 |
size_mode_CN = ["尺寸列表", "只换底", "自定义尺寸"]
|
299 |
size_mode_EN = ["Size List", "Only Change Background", "Custom Size"]
|
300 |
|
|
|
310 |
image_kb_CN = ["不设置", "自定义"]
|
311 |
image_kb_EN = ["Not Set", "Custom"]
|
312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
css = """
|
314 |
#col-left {
|
315 |
margin: 0 auto;
|
|
|
345 |
# ------------ 左半边 UI ----------------
|
346 |
with gr.Column():
|
347 |
img_input = gr.Image(height=400)
|
348 |
+
|
349 |
+
with gr.Row():
|
350 |
+
language_options = gr.Dropdown(
|
351 |
+
choices=language,
|
352 |
+
label="Language",
|
353 |
+
value="中文",
|
354 |
+
elem_id="language",
|
355 |
+
)
|
356 |
+
matting_model_options = gr.Dropdown(
|
357 |
+
choices=matting_model_list,
|
358 |
+
label="Matting Model",
|
359 |
+
value="hivision_modnet",
|
360 |
+
elem_id="matting_model",
|
361 |
+
)
|
362 |
|
363 |
mode_options = gr.Radio(
|
364 |
choices=size_mode_CN,
|
|
|
483 |
img_output_layout: gr.update(label="六寸排版照"),
|
484 |
file_download: gr.update(label="下载调整 KB 大小后的照片"),
|
485 |
}
|
486 |
+
|
487 |
elif language == "English":
|
488 |
return {
|
489 |
size_list_options: gr.update(
|
|
|
607 |
custom_size_wdith,
|
608 |
custom_image_kb_size,
|
609 |
language_options,
|
610 |
+
matting_model_options,
|
611 |
],
|
612 |
outputs=[
|
613 |
img_output_standard,
|
|
|
618 |
],
|
619 |
)
|
620 |
|
621 |
+
demo.launch(server_name=args.host, server_port=args.port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|