Spaces:
Runtime error
Runtime error
Commit Β·
0fb09d5
1
Parent(s): 1150a3a
fix: minor bug
Browse files
app.py
CHANGED
|
@@ -103,55 +103,55 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 103 |
binaryMask[binaryMask >= 255] = 255
|
| 104 |
binaryMask[binaryMask < 255] = 0
|
| 105 |
image = Image.fromarray(result.astype(np.uint8))
|
| 106 |
-
mask = Image.fromarray(binaryMask.astype(np.uint8))
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
|
| 157 |
with gr.Blocks() as interface:
|
|
|
|
| 103 |
binaryMask[binaryMask >= 255] = 255
|
| 104 |
binaryMask[binaryMask < 255] = 0
|
| 105 |
image = Image.fromarray(result.astype(np.uint8))
|
| 106 |
+
mask = Image.fromarray(binaryMask.astype(np.uint8)).convert("RGB")
|
| 107 |
|
| 108 |
+
jewellery_mask = Image.fromarray(
|
| 109 |
+
np.bitwise_and(np.array(mask), np.array(image))
|
| 110 |
+
)
|
| 111 |
+
arr_orig = np.array(grayscale(mask))
|
| 112 |
|
| 113 |
+
image = cv2.inpaint(np.array(image), arr_orig, 15, cv2.INPAINT_TELEA)
|
| 114 |
+
image = Image.fromarray(image)
|
| 115 |
|
| 116 |
+
arr = arr_orig.copy()
|
| 117 |
+
mask_y = np.where(arr == arr[arr != 0][0])[0][0]
|
| 118 |
+
arr[mask_y:, :] = 255
|
| 119 |
|
| 120 |
+
new = Image.fromarray(arr)
|
| 121 |
|
| 122 |
+
mask = new.copy()
|
| 123 |
|
| 124 |
+
orig_size = image.size
|
| 125 |
|
| 126 |
+
image = image.resize((512, 512))
|
| 127 |
+
mask = mask.resize((512, 512))
|
| 128 |
|
| 129 |
+
results = []
|
| 130 |
+
prompt = f" South Indian Saree, properly worn, natural setting, elegant, natural look, neckline without jewellery, simple"
|
| 131 |
+
negative_prompt = "necklaces, jewellery, jewelry, necklace, neckpiece, garland, chain, neck wear, jewelled neck, jeweled neck, necklace on neck, jewellery on neck, accessories, watermark, text, changed background, wider body, narrower body, bad proportions, extra limbs, mutated hands, changed sizes, altered proportions, unnatural body proportions, blury, ugly"
|
| 132 |
|
| 133 |
+
output = pipeline(
|
| 134 |
+
prompt=prompt,
|
| 135 |
+
negative_prompt=negative_prompt,
|
| 136 |
+
image=image,
|
| 137 |
+
mask_image=mask,
|
| 138 |
+
strength=0.95,
|
| 139 |
+
guidance_score=9,
|
| 140 |
+
# generator = torch.Generator("cuda").manual_seed(42)
|
| 141 |
+
).images[0]
|
| 142 |
|
| 143 |
+
output = output.resize(orig_size)
|
| 144 |
+
temp_generated = np.bitwise_and(
|
| 145 |
+
np.array(output),
|
| 146 |
+
np.bitwise_not(np.array(Image.fromarray(arr_orig).convert("RGB"))),
|
| 147 |
+
)
|
| 148 |
+
results.append(temp_generated)
|
| 149 |
|
| 150 |
+
results = [
|
| 151 |
+
Image.fromarray(np.bitwise_or(x, np.array(jewellery_mask))) for x in results
|
| 152 |
+
]
|
| 153 |
+
clear_func()
|
| 154 |
+
return results[0]
|
| 155 |
|
| 156 |
|
| 157 |
with gr.Blocks() as interface:
|