Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,25 @@ from ui import build_ui
|
|
4 |
from overlay import apply_hairstyle
|
5 |
from segmentation import segment_image, estimate_landmarks
|
6 |
|
|
|
7 |
ASSETS_DIR = Path("assets/hairstyles")
|
8 |
|
9 |
def get_hairstyle_list():
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def try_on(user_image, style_name):
|
13 |
-
|
|
|
14 |
return None
|
|
|
|
|
|
|
15 |
mask = segment_image(user_image)
|
16 |
landmarks = estimate_landmarks(user_image) # optional
|
17 |
style_path = str(ASSETS_DIR / style_name)
|
@@ -19,6 +30,8 @@ def try_on(user_image, style_name):
|
|
19 |
|
20 |
def launch():
|
21 |
styles = get_hairstyle_list()
|
|
|
|
|
22 |
demo = build_ui(try_on, styles)
|
23 |
demo.launch()
|
24 |
|
|
|
4 |
from overlay import apply_hairstyle
|
5 |
from segmentation import segment_image, estimate_landmarks
|
6 |
|
7 |
+
# Folder containing your PNG hairstyle overlays
|
8 |
ASSETS_DIR = Path("assets/hairstyles")
|
9 |
|
10 |
def get_hairstyle_list():
|
11 |
+
"""Return sorted list of PNG files in the assets/hairstyles folder."""
|
12 |
+
if not ASSETS_DIR.exists():
|
13 |
+
print("⚠️ hairstyles folder not found:", ASSETS_DIR)
|
14 |
+
return []
|
15 |
+
styles = sorted([f.name for f in ASSETS_DIR.glob("*.png") if f.is_file()])
|
16 |
+
print("✅ Found hairstyles:", styles)
|
17 |
+
return styles
|
18 |
|
19 |
def try_on(user_image, style_name):
|
20 |
+
"""Main try-on function: segments hair, aligns style, blends result."""
|
21 |
+
if user_image is None:
|
22 |
return None
|
23 |
+
if not style_name:
|
24 |
+
print("⚠️ No hairstyle selected")
|
25 |
+
return user_image
|
26 |
mask = segment_image(user_image)
|
27 |
landmarks = estimate_landmarks(user_image) # optional
|
28 |
style_path = str(ASSETS_DIR / style_name)
|
|
|
30 |
|
31 |
def launch():
|
32 |
styles = get_hairstyle_list()
|
33 |
+
if not styles:
|
34 |
+
print("⚠️ No PNG hairstyles found in", ASSETS_DIR)
|
35 |
demo = build_ui(try_on, styles)
|
36 |
demo.launch()
|
37 |
|