leonelhs commited on
Commit
6142843
·
1 Parent(s): 1d37e15

init space

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +12 -1
  3. app.py +88 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea
README.md CHANGED
@@ -11,4 +11,15 @@ license: mit
11
  short_description: yolo human parser
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
11
  short_description: yolo human parser
12
  ---
13
 
14
+ ## Yolo human parser
15
+ This repository is the result of a deep investigation across multiple sources.
16
+ Opaque or redundant code has been removed to make the implementation easier to study and extend.
17
+ ## Acknowledgments
18
+ This work integrates code and concepts from several repositories.
19
+ For proper attribution, please refer to the following sources (or notify us if any are missing):
20
+ - [Yolo](https://github.com/ultralytics/ultralytics)
21
+ - [MnLgt](https://huggingface.co/MnLgt/yolo-human-parse)
22
+ - [Self Space](https://huggingface.co/spaces/leonelhs/human-parser)
23
+ ## Contact
24
+ For questions, comments, or feedback, please contact:
25
+ 📧 **leonelhs@gmail.com**
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #######################################################################################
2
+ #
3
+ # MIT License
4
+ #
5
+ # Copyright (c) [2025] [leonelhs@gmail.com]
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+ #######################################################################################
26
+ #
27
+ # This project is one of several repositories exploring image segmentation techniques.
28
+ # All related projects and interactive demos can be found at:
29
+ # https://huggingface.co/spaces/leonelhs/removators
30
+ # huggingface: https://huggingface.co/spaces/leonelhs/human-parser
31
+ #
32
+ from itertools import islice
33
+
34
+ import gradio as gr
35
+ import numpy as np
36
+ from PIL import Image
37
+ from ultralytics import YOLO
38
+ from huggingface_hub import hf_hub_download
39
+
40
+ # model = YOLO("yolo11x-seg.pt") # only to test official model
41
+
42
+ REPO_ID = "MnLgt/yolo-human-parse"
43
+ model_path = hf_hub_download(repo_id=REPO_ID, filename="yolo-human-parse-epoch-125.pt")
44
+ model = YOLO(model_path)
45
+
46
+ # use for show bounding boxes
47
+ def predict_box(image):
48
+ sections = []
49
+ results = model(image)[0] # predict on an image
50
+ for result in results.boxes:
51
+ box = np.asarray(result.xyxy)[0]
52
+ label = results.names[int(result.cls)]
53
+ sections.append(((int(box[0]), int(box[1]), int(box[2]), int(box[3])), label))
54
+ return image, sections
55
+
56
+
57
+ def predict(image):
58
+ sections = []
59
+ results = model(image)[0] # predict on an image
60
+ for box, mask in zip(results.boxes, results.masks):
61
+ label = results.names[int(box.cls)]
62
+ data = np.asarray(mask.data)
63
+ sections.append((data, label))
64
+
65
+ width = results.masks.shape[1]
66
+ height = results.masks.shape[2]
67
+ image = image.resize((height, width), Image.Resampling.BILINEAR)
68
+ return image, sections
69
+
70
+ with gr.Blocks(title="Yolo human parser") as app:
71
+ navbar = gr.Navbar(visible=True, main_page_name="Workspace")
72
+ gr.Markdown("## Yolo human parser")
73
+ with gr.Row():
74
+ with gr.Column(scale=1):
75
+ inp = gr.Image(type="pil", label="Upload Image")
76
+ btn_predict = gr.Button("Segment")
77
+ with gr.Column(scale=2):
78
+ out = gr.AnnotatedImage(label="Segments annotated")
79
+
80
+ btn_predict.click(predict, inputs=[inp], outputs=[out])
81
+
82
+ with app.route("Readme", "/readme"):
83
+ with open("README.md") as f:
84
+ for line in islice(f, 12, None):
85
+ gr.Markdown(line.strip())
86
+
87
+ app.launch(share=False, debug=True, show_error=True, mcp_server=True, pwa=True)
88
+ app.queue()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch>=2.8.0
2
+ ultralytics>=8.3.203
3
+ pillow~=11.0.0