Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,37 +31,53 @@ def process_mask(mask):
|
|
| 31 |
|
| 32 |
@spaces.GPU
|
| 33 |
def clothing_try_on(image, mask):
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
image=image,
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
def launch_interface():
|
| 67 |
"""Launch the Gradio interface."""
|
|
|
|
| 31 |
|
| 32 |
@spaces.GPU
|
| 33 |
def clothing_try_on(image, mask):
|
| 34 |
+
jewellery_mask = Image.fromarray(
|
| 35 |
+
np.bitwise_and(np.array(mask), np.array(image))
|
| 36 |
+
)
|
| 37 |
+
arr_orig = np.array(grayscale(mask))
|
| 38 |
+
|
| 39 |
+
image = cv2.inpaint(np.array(image), arr_orig, 15, cv2.INPAINT_TELEA)
|
| 40 |
+
image = Image.fromarray(image)
|
| 41 |
+
|
| 42 |
+
arr = arr_orig.copy()
|
| 43 |
+
mask_y = np.where(arr == arr[arr != 0][0])[0][0]
|
| 44 |
+
arr[mask_y:, :] = 255
|
| 45 |
+
|
| 46 |
+
new = Image.fromarray(arr)
|
| 47 |
+
|
| 48 |
+
mask = new.copy()
|
| 49 |
+
|
| 50 |
+
orig_size = image.size
|
| 51 |
+
|
| 52 |
+
image = image.resize((512, 512))
|
| 53 |
+
mask = mask.resize((512, 512))
|
| 54 |
+
|
| 55 |
+
results = []
|
| 56 |
+
prompt = f" South Indian Saree, properly worn, natural setting, elegant, natural look, neckline without jewellery, simple"
|
| 57 |
+
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"
|
| 58 |
+
|
| 59 |
+
output = pipeline(
|
| 60 |
+
prompt=prompt,
|
| 61 |
+
negative_prompt=negative_prompt,
|
| 62 |
+
image=image,
|
| 63 |
+
mask_image=mask,
|
| 64 |
+
strength=0.95,
|
| 65 |
+
guidance_score=9,
|
| 66 |
+
# generator = torch.Generator("cuda").manual_seed(42)
|
| 67 |
+
).images[0]
|
| 68 |
+
|
| 69 |
+
output = output.resize(orig_size)
|
| 70 |
+
temp_generated = np.bitwise_and(
|
| 71 |
+
np.array(output),
|
| 72 |
+
np.bitwise_not(np.array(Image.fromarray(arr_orig).convert("RGB"))),
|
| 73 |
+
)
|
| 74 |
+
results.append(temp_generated)
|
| 75 |
+
|
| 76 |
+
results = [
|
| 77 |
+
Image.fromarray(np.bitwise_or(x, np.array(jewellery_mask))) for x in results
|
| 78 |
+
]
|
| 79 |
+
clear_func()
|
| 80 |
+
return results[0]
|
| 81 |
|
| 82 |
def launch_interface():
|
| 83 |
"""Launch the Gradio interface."""
|