Spaces:
Sleeping
Sleeping
New update
#1
by CREATORJD - opened
- README.md +8 -48
- app.py +0 -106
- requirements.txt +0 -7
README.md
CHANGED
|
@@ -1,54 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title: Alpeccaai
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
Whole-body 2D pose estimation (DWPose / RTMPose via `rtmlib`) for **RIGFORGE**.
|
| 16 |
-
Returns keypoints in the exact JSON shape RIGFORGE reads under
|
| 17 |
-
**AI keypoints → Import pose keypoints**, and exposes a `/detect` endpoint the
|
| 18 |
-
in-tool **⚡ Detect via HF Space** button calls.
|
| 19 |
-
|
| 20 |
-
## Deploy (replace the starter template)
|
| 21 |
-
```bash
|
| 22 |
-
git clone https://huggingface.co/spaces/CREATORJD/Alpeccaai
|
| 23 |
-
cd Alpeccaai
|
| 24 |
-
# copy app.py, requirements.txt, README.md into this folder (overwrite app.py)
|
| 25 |
-
git add app.py requirements.txt README.md
|
| 26 |
-
git commit -m "RIGFORGE pose endpoint (DWPose -> rigpose.json)"
|
| 27 |
-
git push
|
| 28 |
-
```
|
| 29 |
-
Keep **Hardware = ZeroGPU** in Space settings. The model is built lazily inside
|
| 30 |
-
the `@spaces.GPU` function so CUDA is visible during the call; it falls back to
|
| 31 |
-
CPU automatically (fine for single images).
|
| 32 |
-
|
| 33 |
-
## Make the one-click button work
|
| 34 |
-
Set the Space **Visibility = Public** (Settings → Visibility). Then in RIGFORGE,
|
| 35 |
-
type `CREATORJD/Alpeccaai` into the Space field and click **⚡ Detect via HF Space**.
|
| 36 |
-
A private Space can't be called from the static HTML — use the Colab notebook or
|
| 37 |
-
manual import instead.
|
| 38 |
-
|
| 39 |
-
## Output format
|
| 40 |
-
```json
|
| 41 |
-
{
|
| 42 |
-
"format": "coco17",
|
| 43 |
-
"canvas_width": 1122, "canvas_height": 1402,
|
| 44 |
-
"keypoints": [[x, y, score], ...17],
|
| 45 |
-
"people": [{ "pose_keypoints_2d": [x,y,s, ...] }]
|
| 46 |
-
}
|
| 47 |
-
```
|
| 48 |
-
`canvas_width/height` let RIGFORGE scale coordinates to its working image exactly.
|
| 49 |
-
|
| 50 |
-
## Notes
|
| 51 |
-
- Feed **one** figure. For a character sheet, crop the FRONT panel first.
|
| 52 |
-
- For heavily stylized poses, swap in an anime-trained model (Shuhong Chen,
|
| 53 |
-
*Pose Estimation of Illustrated Characters*, WACV 2022) — output maps into the
|
| 54 |
-
same importer.
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Alpeccaai
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.18.0
|
| 8 |
+
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
short_description: 'Advanced ai prototype '
|
| 12 |
---
|
| 13 |
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
DELETED
|
@@ -1,106 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Alpeccaai Pose — Hugging Face Space (ZeroGPU)
|
| 3 |
-
Runs DWPose / RTMPose whole-body 2D pose via rtmlib and returns keypoint JSON
|
| 4 |
-
in the exact format RIGFORGE's "AI keypoints -> Import pose keypoints" reads.
|
| 5 |
-
|
| 6 |
-
Endpoint: /detect (the RIGFORGE "Detect via HF Space" button calls this).
|
| 7 |
-
"""
|
| 8 |
-
import os, json, tempfile
|
| 9 |
-
import numpy as np
|
| 10 |
-
import cv2
|
| 11 |
-
import gradio as gr
|
| 12 |
-
|
| 13 |
-
# ZeroGPU: CUDA is only visible INSIDE a @spaces.GPU function, so the model is
|
| 14 |
-
# built lazily on first call (see get_model). Off ZeroGPU this is a no-op.
|
| 15 |
-
try:
|
| 16 |
-
import spaces
|
| 17 |
-
gpu = spaces.GPU(duration=60)
|
| 18 |
-
except Exception:
|
| 19 |
-
def gpu(fn):
|
| 20 |
-
return fn
|
| 21 |
-
|
| 22 |
-
# COCO-17 body order == first 17 COCO-WholeBody points == RIGFORGE's order:
|
| 23 |
-
# 0 nose 1 L_eye 2 R_eye 3 L_ear 4 R_ear 5 L_sho 6 R_sho 7 L_elb 8 R_elb
|
| 24 |
-
# 9 L_wri 10 R_wri 11 L_hip 12 R_hip 13 L_knee 14 R_knee 15 L_ank 16 R_ank
|
| 25 |
-
SKELETON = [(5,7),(7,9),(6,8),(8,10),(5,6),(11,12),(5,11),(6,12),
|
| 26 |
-
(11,13),(13,15),(12,14),(14,16),(0,5),(0,6)]
|
| 27 |
-
|
| 28 |
-
_model = None
|
| 29 |
-
def get_model():
|
| 30 |
-
global _model
|
| 31 |
-
if _model is None:
|
| 32 |
-
import onnxruntime as ort
|
| 33 |
-
from rtmlib import Wholebody
|
| 34 |
-
dev = "cuda" if "CUDAExecutionProvider" in ort.get_available_providers() else "cpu"
|
| 35 |
-
_model = Wholebody(mode="balanced", backend="onnxruntime", device=dev)
|
| 36 |
-
return _model
|
| 37 |
-
|
| 38 |
-
def _openpose18(b):
|
| 39 |
-
"""COCO-17 -> OpenPose-COCO18 flat list (neck = shoulder midpoint)."""
|
| 40 |
-
neck = [(b[5][0]+b[6][0])/2, (b[5][1]+b[6][1])/2, min(b[5][2], b[6][2])]
|
| 41 |
-
order = [b[0], neck, b[6], b[8], b[10], b[5], b[7], b[9],
|
| 42 |
-
b[12], b[14], b[16], b[11], b[13], b[15], b[2], b[1], b[4], b[3]]
|
| 43 |
-
flat = []
|
| 44 |
-
for x, y, s in order:
|
| 45 |
-
flat += [float(x), float(y), float(s)]
|
| 46 |
-
return flat
|
| 47 |
-
|
| 48 |
-
@gpu
|
| 49 |
-
def detect(image, conf=0.3):
|
| 50 |
-
if image is None:
|
| 51 |
-
raise gr.Error("Upload a single, isolated character figure (not a sheet).")
|
| 52 |
-
rgb = np.array(image.convert("RGB"))
|
| 53 |
-
bgr = rgb[:, :, ::-1].copy()
|
| 54 |
-
h, w = bgr.shape[:2]
|
| 55 |
-
|
| 56 |
-
kpts, scores = get_model()(bgr)
|
| 57 |
-
if kpts is None or len(kpts) == 0:
|
| 58 |
-
raise gr.Error("No person detected. Use a clean front T/A-pose crop.")
|
| 59 |
-
|
| 60 |
-
p = int(np.argmax(scores.mean(axis=1)))
|
| 61 |
-
kp, sc = kpts[p], scores[p]
|
| 62 |
-
body = [[float(kp[i][0]), float(kp[i][1]), float(sc[i])] for i in range(17)]
|
| 63 |
-
|
| 64 |
-
out = {
|
| 65 |
-
"format": "coco17",
|
| 66 |
-
"canvas_width": int(w), "canvas_height": int(h),
|
| 67 |
-
"keypoints": body,
|
| 68 |
-
"people": [{"pose_keypoints_2d": _openpose18(body)}],
|
| 69 |
-
"model": "rtmlib.Wholebody(balanced)",
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
prev = rgb.copy()
|
| 73 |
-
r = max(3, w // 200); lw = max(2, w // 300)
|
| 74 |
-
for x, y, s in body:
|
| 75 |
-
if s >= conf:
|
| 76 |
-
cv2.circle(prev, (int(x), int(y)), r, (61, 240, 224), -1)
|
| 77 |
-
for a, b in SKELETON:
|
| 78 |
-
if body[a][2] >= conf and body[b][2] >= conf:
|
| 79 |
-
cv2.line(prev, (int(body[a][0]), int(body[a][1])),
|
| 80 |
-
(int(body[b][0]), int(body[b][1])), (255, 61, 127), lw)
|
| 81 |
-
|
| 82 |
-
path = os.path.join(tempfile.gettempdir(), "rigpose.json")
|
| 83 |
-
with open(path, "w") as f:
|
| 84 |
-
json.dump(out, f, indent=2)
|
| 85 |
-
return prev, path
|
| 86 |
-
|
| 87 |
-
with gr.Blocks(title="Alpeccaai Pose") as demo:
|
| 88 |
-
gr.Markdown(
|
| 89 |
-
"# Alpeccaai Pose — DWPose keypoints\n"
|
| 90 |
-
"Upload **one isolated character figure** (front T/A-pose is best — *not* a "
|
| 91 |
-
"multi-pose reference sheet). Returns whole-body 2D keypoints as JSON for "
|
| 92 |
-
"RIGFORGE → **AI keypoints → Import pose keypoints**, or call `/detect` from "
|
| 93 |
-
"the in-tool **Detect via HF Space** button."
|
| 94 |
-
)
|
| 95 |
-
with gr.Row():
|
| 96 |
-
inp = gr.Image(type="pil", label="Single character figure")
|
| 97 |
-
with gr.Column():
|
| 98 |
-
conf = gr.Slider(0.0, 1.0, value=0.3, label="Keypoint confidence threshold")
|
| 99 |
-
btn = gr.Button("Detect", variant="primary")
|
| 100 |
-
with gr.Row():
|
| 101 |
-
out_img = gr.Image(label="Detected skeleton")
|
| 102 |
-
out_file = gr.File(label="rigpose.json")
|
| 103 |
-
btn.click(detect, inputs=[inp, conf], outputs=[out_img, out_file], api_name="detect")
|
| 104 |
-
|
| 105 |
-
if __name__ == "__main__":
|
| 106 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
DELETED
|
@@ -1,7 +0,0 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
pydantic==2.10.6
|
| 3 |
-
rtmlib
|
| 4 |
-
onnxruntime-gpu
|
| 5 |
-
opencv-python-headless
|
| 6 |
-
numpy
|
| 7 |
-
pillow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|