Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,256 +1,188 @@
|
|
| 1 |
-
import os,
|
| 2 |
-
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
-
import gradio as gr
|
| 5 |
-
|
| 6 |
-
# Your hairstyles live here:
|
| 7 |
-
HAIR_DIR = "hair"
|
| 8 |
-
|
| 9 |
-
# Optional heavy deps (installed via requirements.txt)
|
| 10 |
-
try:
|
| 11 |
-
import cv2
|
| 12 |
-
import mediapipe as mp
|
| 13 |
-
MP_AVAILABLE = True
|
| 14 |
-
except Exception:
|
| 15 |
-
MP_AVAILABLE = False
|
| 16 |
-
|
| 17 |
-
APP_TITLE = "Salon Hairstyle Virtual Try-On — Pro Demo"
|
| 18 |
-
|
| 19 |
-
# --------------------------
|
| 20 |
-
# Asset loading / utilities
|
| 21 |
-
# --------------------------
|
| 22 |
-
def list_hairstyle_files():
|
| 23 |
-
files = sorted(glob.glob(os.path.join(HAIR_DIR, "*.png")))
|
| 24 |
-
labels = [os.path.basename(f).replace(".png","").replace("_"," ").title() for f in files]
|
| 25 |
-
thumbs = [f for f in files] # Gradio Gallery accepts path strings
|
| 26 |
-
return labels, files, thumbs
|
| 27 |
-
|
| 28 |
-
def ensure_rgba(im: Image.Image) -> Image.Image:
|
| 29 |
-
return im if im.mode == "RGBA" else im.convert("RGBA")
|
| 30 |
-
|
| 31 |
-
def overlay_rgba(base: Image.Image, overlay: Image.Image, x: int, y: int) -> Image.Image:
|
| 32 |
-
base = ensure_rgba(base)
|
| 33 |
-
overlay = ensure_rgba(overlay)
|
| 34 |
-
bw, bh = base.size
|
| 35 |
-
ow, oh = overlay.size
|
| 36 |
-
if ow <= 0 or oh <= 0:
|
| 37 |
-
return base
|
| 38 |
-
x1, y1 = max(0, x), max(0, y)
|
| 39 |
-
x2, y2 = min(bw, x + ow), min(bh, y + oh)
|
| 40 |
-
if x1 >= x2 or y1 >= y2:
|
| 41 |
-
return base
|
| 42 |
-
crop = overlay.crop((x1 - x, y1 - y, x2 - x, y2 - y))
|
| 43 |
-
region = base.crop((x1, y1, x2, y2))
|
| 44 |
-
region = Image.alpha_composite(region, crop)
|
| 45 |
-
base.paste(region, (x1, y1))
|
| 46 |
-
return base
|
| 47 |
-
|
| 48 |
-
# --------------------------
|
| 49 |
-
# Face detection / anchoring
|
| 50 |
-
# --------------------------
|
| 51 |
-
def detect_face_keypoints(np_img):
|
| 52 |
-
"""
|
| 53 |
-
Returns dict:
|
| 54 |
-
bbox: (x1,y1,x2,y2)
|
| 55 |
-
temples: (lx,ly, rx,ry)
|
| 56 |
-
forehead_y: int
|
| 57 |
-
"""
|
| 58 |
-
h, w = np_img.shape[:2]
|
| 59 |
-
|
| 60 |
-
def fallback():
|
| 61 |
-
cx, cy = w // 2, int(h * 0.42)
|
| 62 |
-
bw, bh = int(w * 0.4), int(h * 0.45)
|
| 63 |
-
x1, y1 = max(0, cx - bw // 2), max(0, cy - bh // 2)
|
| 64 |
-
x2, y2 = min(w, x1 + bw), min(h, y1 + bh)
|
| 65 |
-
return {
|
| 66 |
-
"bbox": (x1, y1, x2, y2),
|
| 67 |
-
"temples": (x1, (y1 + y2) // 2, x2, (y1 + y2) // 2),
|
| 68 |
-
"forehead_y": max(0, int(y1 - 0.1 * (y2 - y1))),
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
if not MP_AVAILABLE:
|
| 72 |
-
return fallback()
|
| 73 |
-
|
| 74 |
-
mpfm = mp.solutions.face_mesh
|
| 75 |
-
with mpfm.FaceMesh(static_image_mode=True, max_num_faces=1, refine_landmarks=False) as fm:
|
| 76 |
-
rgb = cv2.cvtColor(np_img, cv2.COLOR_BGR2RGB) if np_img.shape[2] == 3 else np_img[..., :3]
|
| 77 |
-
res = fm.process(rgb)
|
| 78 |
-
if not res.multi_face_landmarks:
|
| 79 |
-
return fallback()
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
lm = res.multi_face_landmarks[0].landmark
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
rot_total = auto_deg + rotation_deg
|
| 124 |
-
hair_resized = hair_resized.rotate(rot_total, expand=True)
|
| 125 |
-
|
| 126 |
-
# Anchor at temple midpoint, above forehead
|
| 127 |
-
midx = int((lx + rx) / 2)
|
| 128 |
-
anchor_x = int(midx - hair_resized.width / 2)
|
| 129 |
-
anchor_y = int(forehead_y - hair_resized.height * 0.45)
|
| 130 |
-
|
| 131 |
-
# Apply shifts (percent of image size)
|
| 132 |
-
img_w, img_h = base.size
|
| 133 |
-
anchor_x += int(lr_shift_pct * img_w / 100.0) # +right, -left
|
| 134 |
-
anchor_y += int(ud_shift_pct * img_h / 100.0) # +down, -up
|
| 135 |
-
|
| 136 |
-
out = overlay_rgba(base, hair_resized, anchor_x, anchor_y).convert("RGB")
|
| 137 |
return out
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
ud2 = gr.Slider(-30, 30, value=0, step=0.5, label="Up ↕ Down shift (%)")
|
| 242 |
-
rot2 = gr.Slider(-30, 30, value=0, step=0.5, label="Rotation (°)")
|
| 243 |
-
out_live = gr.Image(label="Live Preview", interactive=False, height=420)
|
| 244 |
-
|
| 245 |
-
def live_process(frame, label, s, lrp, udp, r):
|
| 246 |
-
labels, files, _ = list_hairstyle_files()
|
| 247 |
-
if frame is None or not labels or label not in labels:
|
| 248 |
-
return frame
|
| 249 |
-
path = files[labels.index(label)]
|
| 250 |
-
return place_and_render(frame, path, s, lrp, udp, r)
|
| 251 |
-
|
| 252 |
-
cam.stream(fn=live_process, inputs=[cam, hair_dd2, scale2, lr2, ud2, rot2], outputs=out_live)
|
| 253 |
-
demo.load(fn=refresh_dropdown_only, inputs=None, outputs=hair_dd2)
|
| 254 |
|
| 255 |
if __name__ == "__main__":
|
| 256 |
demo.launch()
|
|
|
|
| 1 |
+
import os, json, tempfile
|
| 2 |
+
import cv2, numpy as np, gradio as gr, mediapipe as mp
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
HAIR_DIR = "assets/hairstyles"
|
| 6 |
+
META_PATH = os.path.join(HAIR_DIR, "meta.json")
|
| 7 |
+
|
| 8 |
+
# ---------- Load hairstyle list ----------
|
| 9 |
+
def load_hairstyles():
|
| 10 |
+
files = [f for f in os.listdir(HAIR_DIR) if f.lower().endswith(".png")]
|
| 11 |
+
files.sort()
|
| 12 |
+
return files
|
| 13 |
+
|
| 14 |
+
HAIR_FILES = load_hairstyles()
|
| 15 |
+
|
| 16 |
+
# ---------- Optional per-style anchor metadata ----------
|
| 17 |
+
def load_meta():
|
| 18 |
+
if os.path.exists(META_PATH):
|
| 19 |
+
with open(META_PATH, "r") as f:
|
| 20 |
+
return json.load(f)
|
| 21 |
+
return {}
|
| 22 |
+
|
| 23 |
+
META = load_meta()
|
| 24 |
+
|
| 25 |
+
# ---------- MediaPipe ----------
|
| 26 |
+
mp_face_mesh = mp.solutions.face_mesh
|
| 27 |
+
mp_selfie_seg = mp.solutions.selfie_segmentation
|
| 28 |
+
|
| 29 |
+
LM = {"left_eye_outer": 33, "right_eye_outer": 263, "mid_forehead": 10}
|
| 30 |
+
|
| 31 |
+
def detect_face_keypoints(img_bgr):
|
| 32 |
+
h, w = img_bgr.shape[:2]
|
| 33 |
+
with mp_face_mesh.FaceMesh(
|
| 34 |
+
static_image_mode=True, max_num_faces=1, refine_landmarks=True,
|
| 35 |
+
min_detection_confidence=0.6
|
| 36 |
+
) as fm:
|
| 37 |
+
res = fm.process(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
|
| 38 |
+
if not res.multi_face_landmarks:
|
| 39 |
+
return None
|
| 40 |
lm = res.multi_face_landmarks[0].landmark
|
| 41 |
+
def xy(i): return np.array([lm[i].x*w, lm[i].y*h], dtype=np.float32)
|
| 42 |
+
return np.stack([xy(LM["left_eye_outer"]), xy(LM["right_eye_outer"]), xy(LM["mid_forehead"])])
|
| 43 |
+
|
| 44 |
+
def person_mask(img_bgr):
|
| 45 |
+
"""FR-4: person segmentation (rough head isolation)."""
|
| 46 |
+
with mp_selfie_seg.SelfieSegmentation(model_selection=1) as seg:
|
| 47 |
+
rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
|
| 48 |
+
m = seg.process(rgb).segmentation_mask
|
| 49 |
+
# Binarize + feather
|
| 50 |
+
mask = (m > 0.5).astype(np.float32)
|
| 51 |
+
mask = cv2.GaussianBlur(mask, (35,35), 0) # soft edges
|
| 52 |
+
return mask
|
| 53 |
+
|
| 54 |
+
def load_hair_png(name):
|
| 55 |
+
path = os.path.join(HAIR_DIR, name)
|
| 56 |
+
hair = cv2.imread(path, cv2.IMREAD_UNCHANGED) # BGRA
|
| 57 |
+
if hair is None or hair.shape[2] != 4:
|
| 58 |
+
raise ValueError(f"Invalid hair asset: {name}")
|
| 59 |
+
return hair
|
| 60 |
+
|
| 61 |
+
def hair_reference_points(hair_bgra, filename):
|
| 62 |
+
"""Three anchors on hair image; override via meta.json if present."""
|
| 63 |
+
h, w = hair_bgra.shape[:2]
|
| 64 |
+
if filename in META:
|
| 65 |
+
pts = np.array(META[filename], dtype=np.float32)
|
| 66 |
+
if pts.shape == (3,2):
|
| 67 |
+
return pts
|
| 68 |
+
# Sensible defaults; tune per style later
|
| 69 |
+
pL = np.array([0.30*w, 0.60*h], dtype=np.float32)
|
| 70 |
+
pR = np.array([0.70*w, 0.60*h], dtype=np.float32)
|
| 71 |
+
pM = np.array([0.50*w, 0.40*h], dtype=np.float32)
|
| 72 |
+
return np.stack([pL, pR, pM], axis=0)
|
| 73 |
+
|
| 74 |
+
def warp_and_alpha_blend(base_bgr, hair_bgra, M, opacity=1.0):
|
| 75 |
+
H, W = base_bgr.shape[:2]
|
| 76 |
+
hair_rgb = hair_bgra[:,:,:3]
|
| 77 |
+
hair_a = hair_bgra[:,:,3] / 255.0
|
| 78 |
+
hair_warp = cv2.warpAffine(hair_rgb, M, (W, H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_TRANSPARENT)
|
| 79 |
+
a_warp = cv2.warpAffine(hair_a, M, (W, H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_TRANSPARENT)
|
| 80 |
+
a = np.clip(a_warp * opacity, 0, 1)[..., None]
|
| 81 |
+
out = (a*hair_warp + (1-a)*base_bgr).astype(np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return out
|
| 83 |
|
| 84 |
+
def apply_tryon(image, hairstyle, scale_pct, rot_deg, dx, dy, opacity):
|
| 85 |
+
if image is None or hairstyle is None:
|
| 86 |
+
return None, "Upload an image or turn on webcam, and select a hairstyle."
|
| 87 |
+
|
| 88 |
+
img_bgr = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
| 89 |
+
|
| 90 |
+
kpts = detect_face_keypoints(img_bgr)
|
| 91 |
+
if kpts is None:
|
| 92 |
+
return image, "No face detected. Try a brighter, front-facing photo."
|
| 93 |
+
|
| 94 |
+
hair = load_hair_png(hairstyle)
|
| 95 |
+
hair_pts = hair_reference_points(hair, hairstyle)
|
| 96 |
+
|
| 97 |
+
# Manual tweaks on destination points (user nudges)
|
| 98 |
+
dst = kpts.copy()
|
| 99 |
+
dst[:,0] += dx
|
| 100 |
+
dst[:,1] += dy
|
| 101 |
+
|
| 102 |
+
# Scale + rotate around hair anchor centroid
|
| 103 |
+
center = hair_pts.mean(axis=0)
|
| 104 |
+
theta = np.deg2rad(rot_deg)
|
| 105 |
+
s = max(0.5, scale_pct/100.0)
|
| 106 |
+
R = np.array([[np.cos(theta), -np.sin(theta)],
|
| 107 |
+
[np.sin(theta), np.cos(theta)]], dtype=np.float32)
|
| 108 |
+
hair_pts_adj = (hair_pts - center) @ R.T * s + center
|
| 109 |
+
|
| 110 |
+
M, _ = cv2.estimateAffinePartial2D(hair_pts_adj, dst, method=cv2.LMEDS)
|
| 111 |
+
if M is None:
|
| 112 |
+
return image, "Could not compute alignment."
|
| 113 |
+
|
| 114 |
+
# FR-4: Soft-limit overlay to head area
|
| 115 |
+
out = warp_and_alpha_blend(img_bgr, hair, M, opacity=opacity)
|
| 116 |
+
head = person_mask(img_bgr)
|
| 117 |
+
head3 = head[...,None]
|
| 118 |
+
out = (head3*out + (1-head3)*img_bgr).astype(np.uint8)
|
| 119 |
+
|
| 120 |
+
out_rgb = cv2.cvtColor(out, cv2.COLOR_BGR2RGB)
|
| 121 |
+
return out_rgb, "OK"
|
| 122 |
+
|
| 123 |
+
def save_png(img):
|
| 124 |
+
if img is None:
|
| 125 |
+
return None
|
| 126 |
+
p = os.path.join(tempfile.gettempdir(), "tryon_result.png")
|
| 127 |
+
Image.fromarray(img).save(p)
|
| 128 |
+
return p
|
| 129 |
+
|
| 130 |
+
def ui():
|
| 131 |
+
with gr.Blocks(title="Salon Virtual Try-On", css="""
|
| 132 |
+
.gradio-container {max-width: 980px; margin:auto;}
|
| 133 |
+
@media (max-width: 768px){ .gradio-container {padding: 8px;} }
|
| 134 |
+
""") as demo:
|
| 135 |
+
gr.Markdown("## Virtual Try-On (FR1–FR8)\nUpload or use webcam, pick a hairstyle, adjust, and download.")
|
| 136 |
+
with gr.Tabs():
|
| 137 |
+
# -------- Photo tab (FR1, FR3–FR7) --------
|
| 138 |
+
with gr.Tab("Photo"):
|
| 139 |
+
with gr.Row():
|
| 140 |
+
in_img = gr.Image(label="Upload photo (JPEG/PNG)", sources=["upload"], type="pil")
|
| 141 |
+
hair = gr.Radio(choices=HAIR_FILES, value=HAIR_FILES[0] if HAIR_FILES else None, label="Hairstyles")
|
| 142 |
+
with gr.Accordion("Alignment Controls", open=True):
|
| 143 |
+
with gr.Row():
|
| 144 |
+
scale = gr.Slider(50, 200, 100, 1, label="Scale %")
|
| 145 |
+
rot = gr.Slider(-30, 30, 0, 1, label="Rotate (deg)")
|
| 146 |
+
with gr.Row():
|
| 147 |
+
dx = gr.Slider(-200, 200, 0, 1, label="Horizontal Nudge (px)")
|
| 148 |
+
dy = gr.Slider(-200, 200, 0, 1, label="Vertical Nudge (px)")
|
| 149 |
+
opacity = gr.Slider(0.2, 1.0, 1.0, 0.05, label="Hair Opacity")
|
| 150 |
+
|
| 151 |
+
out = gr.Image(label="Result Preview (FR6)")
|
| 152 |
+
status = gr.Markdown()
|
| 153 |
+
|
| 154 |
+
run = gr.Button("Apply (FR5)")
|
| 155 |
+
run.click(
|
| 156 |
+
fn=lambda im,h,s,r,dxv,dyv,op: apply_tryon(im,h,s,r,dxv,dyv,op),
|
| 157 |
+
inputs=[in_img, hair, scale, rot, dx, dy, opacity],
|
| 158 |
+
outputs=[out, status]
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
dl = gr.DownloadButton(label="Download Result (FR7)", file_name="tryon.png")
|
| 162 |
+
dl.click(fn=save_png, inputs=[out], outputs=[dl])
|
| 163 |
+
|
| 164 |
+
gr.Markdown("Share: send the URL of this Space to others once it’s public. (In Spaces, the app URL is shareable.)")
|
| 165 |
+
|
| 166 |
+
# -------- Webcam tab (FR2–FR6) --------
|
| 167 |
+
with gr.Tab("Webcam"):
|
| 168 |
+
cam = gr.Image(sources=["webcam"], streaming=True, type="pil", label="Enable camera to start")
|
| 169 |
+
hair2 = gr.Radio(choices=HAIR_FILES, value=HAIR_FILES[0] if HAIR_FILES else None, label="Hairstyles")
|
| 170 |
+
scale2 = gr.Slider(50, 200, 100, 1, label="Scale %")
|
| 171 |
+
rot2 = gr.Slider(-25, 25, 0, 1, label="Rotate (deg)")
|
| 172 |
+
dx2 = gr.Slider(-150, 150, 0, 1, label="Horizontal Nudge (px)")
|
| 173 |
+
dy2 = gr.Slider(-150, 150, 0, 1, label="Vertical Nudge (px)")
|
| 174 |
+
opacity2 = gr.Slider(0.2, 1.0, 0.95, 0.05, label="Hair Opacity")
|
| 175 |
+
out2 = gr.Image(label="Live Preview")
|
| 176 |
+
|
| 177 |
+
def live(im, h, s, r, dxv, dyv, op):
|
| 178 |
+
res, _ = apply_tryon(im,h,s,r,dxv,dyv,op)
|
| 179 |
+
return res
|
| 180 |
+
|
| 181 |
+
cam.stream(live, inputs=[cam,hair2,scale2,rot2,dx2,dy2,opacity2], outputs=[out2])
|
| 182 |
+
|
| 183 |
+
return demo
|
| 184 |
+
|
| 185 |
+
demo = ui()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
demo.launch()
|