hzaustingg commited on
Commit
cd54ab4
·
1 Parent(s): 4a0c544

Prepare Hugging Face Space deployment

Browse files
Files changed (6) hide show
  1. README-CN.md +20 -2
  2. README.md +20 -2
  3. app.py +8 -0
  4. pyproject.toml +1 -1
  5. requirements.txt +5 -0
  6. scripts/demo_gradio.py +36 -18
README-CN.md CHANGED
@@ -1,8 +1,26 @@
1
- # Nail Try-On Segmentation(YOLOv8s-seg + ONNX Runtime CPU)
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  [English](./README.md) | [中文](./README-CN.md)
4
 
5
- 这是一个用于指甲实例分割与轻量试妆流程的线项目
 
 
 
 
 
 
 
6
 
7
  ## 功能特性
8
 
 
1
+ ---
2
+ title: Nail Segmentation Demo
3
+ emoji: "💅"
4
+ colorFrom: pink
5
+ colorTo: blue
6
+ sdk: gradio
7
+ python_version: "3.10"
8
+ app_file: app.py
9
+ fullWidth: true
10
+ ---
11
+
12
+ # Fingernail instance segmentation and virtual try-on demo built with YOLOv8, ONNX Runtime, and Gradio.
13
 
14
  [English](./README.md) | [中文](./README-CN.md)
15
 
16
+ 这是一个轻量的指甲实例分割与虚拟试妆 Demo,结合了于 YOLOv8 的分割结果、ONNX Runtime CPU 推理,以及简洁的 Gradio 交互界面
17
+
18
+ ## 快速入口
19
+
20
+ - Demo 效果:[静态示例](#demo-效果)
21
+ - 交互 Demo:[Gradio Demo](#gradio-demo)
22
+ - Hugging Face Space:创建一个 Gradio Space 后,直接上传当前 `github_release/` 发布目录
23
+ - Topics:`nail-segmentation`、`virtual-try-on`、`computer-vision`、`instance-segmentation`
24
 
25
  ## 功能特性
26
 
README.md CHANGED
@@ -1,8 +1,26 @@
1
- # Nail Try-On Segmentation (YOLOv8s-seg + ONNX Runtime CPU)
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  [English](./README.md) | [中文](./README-CN.md)
4
 
5
- A baseline project for nail instance segmentation and lightweight try-on workflows.
 
 
 
 
 
 
 
6
 
7
  ## Features
8
 
 
1
+ ---
2
+ title: Nail Segmentation Demo
3
+ emoji: "💅"
4
+ colorFrom: pink
5
+ colorTo: blue
6
+ sdk: gradio
7
+ python_version: "3.10"
8
+ app_file: app.py
9
+ fullWidth: true
10
+ ---
11
+
12
+ # Fingernail instance segmentation and virtual try-on demo built with YOLOv8, ONNX Runtime, and Gradio.
13
 
14
  [English](./README.md) | [中文](./README-CN.md)
15
 
16
+ A lightweight demo for fingernail instance segmentation and virtual try-on workflows, with YOLOv8-based masks, ONNX Runtime CPU inference, and a simple Gradio interface.
17
+
18
+ ## Quick Links
19
+
20
+ - Demo results: [Static examples](#demo-results)
21
+ - Interactive demo: [Gradio demo](#gradio-demo)
22
+ - Hugging Face Space: create a Gradio Space and upload this `github_release/` bundle
23
+ - Topics: `nail-segmentation`, `virtual-try-on`, `computer-vision`, `instance-segmentation`
24
 
25
  ## Features
26
 
app.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from scripts.demo_gradio import build_demo
2
+
3
+
4
+ demo = build_demo()
5
+
6
+
7
+ if __name__ == "__main__":
8
+ demo.launch()
pyproject.toml CHANGED
@@ -1,7 +1,7 @@
1
  [project]
2
  name = "nail-seg-onnx-demo"
3
  version = "0.1.0"
4
- description = "Nail instance segmentation demo with ONNX Runtime CPU and Gradio"
5
  readme = "README.md"
6
  requires-python = ">=3.10,<3.13"
7
  dependencies = [
 
1
  [project]
2
  name = "nail-seg-onnx-demo"
3
  version = "0.1.0"
4
+ description = "Fingernail instance segmentation and virtual try-on demo built with YOLOv8, ONNX Runtime, and Gradio."
5
  readme = "README.md"
6
  requires-python = ">=3.10,<3.13"
7
  dependencies = [
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy>=1.24.0
2
+ opencv-python-headless>=4.8.0
3
+ pillow>=10.0.0
4
+ onnxruntime>=1.17.0,<1.24.0
5
+ gradio>=6.14.0,<7.0.0
scripts/demo_gradio.py CHANGED
@@ -3,7 +3,6 @@ from pathlib import Path
3
 
4
  import cv2
5
  import gradio as gr
6
- import numpy as np
7
 
8
  from onnx_seg_utils import YoloV8SegONNX, render_instances
9
 
@@ -20,24 +19,20 @@ def load_examples(example_dir: Path):
20
  return [[str(p)] for p in files[:12]]
21
 
22
 
23
- def main():
24
- parser = argparse.ArgumentParser()
25
- parser.add_argument("--model", type=str, default="models/nail-seg.onnx")
26
- parser.add_argument("--example_dir", type=str, default="examples/input")
27
- parser.add_argument("--host", type=str, default="127.0.0.1")
28
- parser.add_argument("--port", type=int, default=7860)
29
- parser.add_argument("--conf", type=float, default=0.55)
30
- parser.add_argument("--iou", type=float, default=0.45)
31
- args = parser.parse_args()
32
-
33
- inferencer = YoloV8SegONNX(args.model, conf_thres=args.conf, iou_thres=args.iou)
34
 
35
  def predict(image_np, conf_thr=None, iou_thr=None, mask_thr=None, min_area_ratio=None):
36
  if image_np is None:
37
  return None, None, "Please upload an image first."
38
 
39
- conf_thr = float(args.conf if conf_thr is None else conf_thr)
40
- iou_thr = float(args.iou if iou_thr is None else iou_thr)
41
  mask_thr = float(0.5 if mask_thr is None else mask_thr)
42
  min_area_ratio = float(0.01 if min_area_ratio is None else min_area_ratio)
43
 
@@ -59,7 +54,7 @@ def main():
59
  mask_rgb = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB)
60
  return to_rgb(overlay), mask_rgb, msg
61
 
62
- example_data = load_examples(Path(args.example_dir))
63
 
64
  with gr.Blocks(title="Nail Segmentation Demo (ONNX Runtime CPU)") as demo:
65
  gr.Markdown("## Nail Segmentation Demo (YOLOv8s-seg ONNX Runtime CPU)")
@@ -68,8 +63,8 @@ def main():
68
  with gr.Row():
69
  in_image = gr.Image(type="numpy", label="Input Image")
70
  with gr.Row():
71
- conf_slider = gr.Slider(0.1, 0.95, value=args.conf, step=0.01, label="Confidence")
72
- iou_slider = gr.Slider(0.1, 0.9, value=args.iou, step=0.01, label="NMS IoU")
73
  with gr.Row():
74
  mask_thr_slider = gr.Slider(0.2, 0.8, value=0.5, step=0.01, label="Mask Threshold")
75
  min_area_slider = gr.Slider(0.001, 0.05, value=0.01, step=0.001, label="Min Area Ratio")
@@ -80,11 +75,34 @@ def main():
80
  out_mask = gr.Image(type="numpy", label="Mask (Binary)")
81
  out_text = gr.Textbox(label="Result")
82
 
83
- btn.click(fn=predict, inputs=[in_image, conf_slider, iou_slider, mask_thr_slider, min_area_slider], outputs=[out_overlay, out_mask, out_text])
 
 
 
 
84
 
85
  if example_data:
86
  gr.Examples(examples=example_data, inputs=[in_image], label="Examples")
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  demo.launch(server_name=args.host, server_port=args.port)
89
 
90
 
 
3
 
4
  import cv2
5
  import gradio as gr
 
6
 
7
  from onnx_seg_utils import YoloV8SegONNX, render_instances
8
 
 
19
  return [[str(p)] for p in files[:12]]
20
 
21
 
22
+ def build_demo(
23
+ model_path="models/nail-seg.onnx",
24
+ example_dir="examples/input",
25
+ default_conf=0.55,
26
+ default_iou=0.45,
27
+ ):
28
+ inferencer = YoloV8SegONNX(model_path, conf_thres=default_conf, iou_thres=default_iou)
 
 
 
 
29
 
30
  def predict(image_np, conf_thr=None, iou_thr=None, mask_thr=None, min_area_ratio=None):
31
  if image_np is None:
32
  return None, None, "Please upload an image first."
33
 
34
+ conf_thr = float(default_conf if conf_thr is None else conf_thr)
35
+ iou_thr = float(default_iou if iou_thr is None else iou_thr)
36
  mask_thr = float(0.5 if mask_thr is None else mask_thr)
37
  min_area_ratio = float(0.01 if min_area_ratio is None else min_area_ratio)
38
 
 
54
  mask_rgb = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB)
55
  return to_rgb(overlay), mask_rgb, msg
56
 
57
+ example_data = load_examples(Path(example_dir))
58
 
59
  with gr.Blocks(title="Nail Segmentation Demo (ONNX Runtime CPU)") as demo:
60
  gr.Markdown("## Nail Segmentation Demo (YOLOv8s-seg ONNX Runtime CPU)")
 
63
  with gr.Row():
64
  in_image = gr.Image(type="numpy", label="Input Image")
65
  with gr.Row():
66
+ conf_slider = gr.Slider(0.1, 0.95, value=default_conf, step=0.01, label="Confidence")
67
+ iou_slider = gr.Slider(0.1, 0.9, value=default_iou, step=0.01, label="NMS IoU")
68
  with gr.Row():
69
  mask_thr_slider = gr.Slider(0.2, 0.8, value=0.5, step=0.01, label="Mask Threshold")
70
  min_area_slider = gr.Slider(0.001, 0.05, value=0.01, step=0.001, label="Min Area Ratio")
 
75
  out_mask = gr.Image(type="numpy", label="Mask (Binary)")
76
  out_text = gr.Textbox(label="Result")
77
 
78
+ btn.click(
79
+ fn=predict,
80
+ inputs=[in_image, conf_slider, iou_slider, mask_thr_slider, min_area_slider],
81
+ outputs=[out_overlay, out_mask, out_text],
82
+ )
83
 
84
  if example_data:
85
  gr.Examples(examples=example_data, inputs=[in_image], label="Examples")
86
 
87
+ return demo
88
+
89
+
90
+ def main():
91
+ parser = argparse.ArgumentParser()
92
+ parser.add_argument("--model", type=str, default="models/nail-seg.onnx")
93
+ parser.add_argument("--example_dir", type=str, default="examples/input")
94
+ parser.add_argument("--host", type=str, default="127.0.0.1")
95
+ parser.add_argument("--port", type=int, default=7860)
96
+ parser.add_argument("--conf", type=float, default=0.55)
97
+ parser.add_argument("--iou", type=float, default=0.45)
98
+ args = parser.parse_args()
99
+
100
+ demo = build_demo(
101
+ model_path=args.model,
102
+ example_dir=args.example_dir,
103
+ default_conf=args.conf,
104
+ default_iou=args.iou,
105
+ )
106
  demo.launch(server_name=args.host, server_port=args.port)
107
 
108