Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,9 @@ import cv2 as cv
|
|
10 |
processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
11 |
model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
12 |
|
13 |
-
|
14 |
def change_hair_color(image, selected_color):
|
15 |
-
|
16 |
inputs = processor(images=image, return_tensors="pt")
|
17 |
|
18 |
# Model çıktısını alarak segmentasyon maskesini oluşturun
|
@@ -47,13 +47,14 @@ def change_hair_color(image, selected_color):
|
|
47 |
mor_sac = cv.merge([r, g, r]) # Yeşili azaltarak mora kaydır
|
48 |
|
49 |
# Seçilen renge göre filtreyi uygula
|
50 |
-
if selected_color == "
|
51 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(yesil_sac, yesil_sac, mask=hair_mask), 1, 0)
|
52 |
-
elif selected_color == "
|
53 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(mavi_sac, mavi_sac, mask=hair_mask), 1, 0)
|
54 |
-
elif selected_color == "
|
55 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(sari_sac, sari_sac, mask=hair_mask), 1, 0)
|
56 |
-
elif selected_color == "
|
|
|
57 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(mor_sac, mor_sac, mask=hair_mask), 1, 0)
|
58 |
else:
|
59 |
final_image = image_cv # Orijinal renk
|
@@ -69,11 +70,11 @@ iface = gr.Interface(
|
|
69 |
inputs=[
|
70 |
gr.Image(type="pil"),
|
71 |
gr.Dropdown(
|
72 |
-
choices=["
|
73 |
label="Select Color"
|
74 |
)
|
75 |
],
|
76 |
-
outputs=gr.Image(type="numpy", label="
|
77 |
live=False,
|
78 |
title="Hair Filter",
|
79 |
description="To change hair color, upload an image and select the color you want, then click the Submit button."
|
|
|
10 |
processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
11 |
model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
12 |
|
13 |
+
|
14 |
def change_hair_color(image, selected_color):
|
15 |
+
|
16 |
inputs = processor(images=image, return_tensors="pt")
|
17 |
|
18 |
# Model çıktısını alarak segmentasyon maskesini oluşturun
|
|
|
47 |
mor_sac = cv.merge([r, g, r]) # Yeşili azaltarak mora kaydır
|
48 |
|
49 |
# Seçilen renge göre filtreyi uygula
|
50 |
+
if selected_color == "Green":
|
51 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(yesil_sac, yesil_sac, mask=hair_mask), 1, 0)
|
52 |
+
elif selected_color == "Blue":
|
53 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(mavi_sac, mavi_sac, mask=hair_mask), 1, 0)
|
54 |
+
elif selected_color == "Yellow":
|
55 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(sari_sac, sari_sac, mask=hair_mask), 1, 0)
|
56 |
+
elif selected_color == "Purple
|
57 |
+
":
|
58 |
final_image = cv.addWeighted(image_cv, 1, cv.bitwise_and(mor_sac, mor_sac, mask=hair_mask), 1, 0)
|
59 |
else:
|
60 |
final_image = image_cv # Orijinal renk
|
|
|
70 |
inputs=[
|
71 |
gr.Image(type="pil"),
|
72 |
gr.Dropdown(
|
73 |
+
choices=["Green", "Blue", "Yellow", "Purple"],
|
74 |
label="Select Color"
|
75 |
)
|
76 |
],
|
77 |
+
outputs=gr.Image(type="numpy", label="result"),
|
78 |
live=False,
|
79 |
title="Hair Filter",
|
80 |
description="To change hair color, upload an image and select the color you want, then click the Submit button."
|