Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,52 @@ torch.jit.script = lambda f: f
|
|
15 |
from model.cloth_masker import AutoMasker, vis_mask
|
16 |
from model.pipeline import CatVTONPipeline
|
17 |
from utils import init_weight_dtype, resize_and_crop, resize_and_padding
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def parse_args():
|
21 |
parser = argparse.ArgumentParser(description="Simple example of a training script.")
|
22 |
parser.add_argument(
|
@@ -186,8 +230,9 @@ def submit_function(
|
|
186 |
masked_person = vis_mask(person_image, mask)
|
187 |
save_result_image = image_grid([person_image, masked_person, cloth_image, result_image], 1, 4)
|
188 |
save_result_image.save(result_save_path)
|
|
|
189 |
if show_type == "result only":
|
190 |
-
|
191 |
else:
|
192 |
width, height = person_image.size
|
193 |
if show_type == "input & result":
|
@@ -200,7 +245,11 @@ def submit_function(
|
|
200 |
new_result_image = Image.new("RGB", (width + condition_width + 5, height))
|
201 |
new_result_image.paste(conditions, (0, 0))
|
202 |
new_result_image.paste(result_image, (condition_width + 5, 0))
|
203 |
-
|
|
|
|
|
|
|
|
|
204 |
|
205 |
|
206 |
def person_example_fn(image_path):
|
|
|
15 |
from model.cloth_masker import AutoMasker, vis_mask
|
16 |
from model.pipeline import CatVTONPipeline
|
17 |
from utils import init_weight_dtype, resize_and_crop, resize_and_padding
|
18 |
+
from PIL import Image
|
19 |
|
20 |
+
def add_watermark(main_image, logo_path, position='bottom-right', size_percentage=10):
|
21 |
+
"""
|
22 |
+
Add a watermark to an image
|
23 |
+
Args:
|
24 |
+
main_image (PIL.Image): The main image
|
25 |
+
logo_path (str): Path to the logo image
|
26 |
+
position (str): Position of watermark ('bottom-right', 'bottom-left', 'top-right', 'top-left')
|
27 |
+
size_percentage (int): Size of watermark relative to main image (in percentage)
|
28 |
+
Returns:
|
29 |
+
PIL.Image: Image with watermark
|
30 |
+
"""
|
31 |
+
# Open and resize the logo
|
32 |
+
logo = Image.open(logo_path).convert('RGBA')
|
33 |
+
|
34 |
+
# Calculate the size for the logo
|
35 |
+
main_width, main_height = main_image.size
|
36 |
+
logo_width = int(main_width * size_percentage / 100)
|
37 |
+
logo_height = int(logo.size[1] * (logo_width / logo.size[0]))
|
38 |
+
logo = logo.resize((logo_width, logo_height), Image.Resampling.LANCZOS)
|
39 |
+
|
40 |
+
# Convert main image to RGBA if it isn't already
|
41 |
+
if main_image.mode != 'RGBA':
|
42 |
+
main_image = main_image.convert('RGBA')
|
43 |
+
|
44 |
+
# Create a new blank image with the same size as main image
|
45 |
+
watermarked = Image.new('RGBA', main_image.size, (0, 0, 0, 0))
|
46 |
+
watermarked.paste(main_image, (0, 0))
|
47 |
+
|
48 |
+
# Calculate position
|
49 |
+
if position == 'bottom-right':
|
50 |
+
position = (main_width - logo_width - 10, main_height - logo_height - 10)
|
51 |
+
elif position == 'bottom-left':
|
52 |
+
position = (10, main_height - logo_height - 10)
|
53 |
+
elif position == 'top-right':
|
54 |
+
position = (main_width - logo_width - 10, 10)
|
55 |
+
elif position == 'top-left':
|
56 |
+
position = (10, 10)
|
57 |
+
|
58 |
+
# Paste the logo
|
59 |
+
watermarked.paste(logo, position, logo)
|
60 |
+
|
61 |
+
# Convert back to RGB
|
62 |
+
return watermarked.convert('RGB')
|
63 |
+
|
64 |
def parse_args():
|
65 |
parser = argparse.ArgumentParser(description="Simple example of a training script.")
|
66 |
parser.add_argument(
|
|
|
230 |
masked_person = vis_mask(person_image, mask)
|
231 |
save_result_image = image_grid([person_image, masked_person, cloth_image, result_image], 1, 4)
|
232 |
save_result_image.save(result_save_path)
|
233 |
+
final_image = None
|
234 |
if show_type == "result only":
|
235 |
+
final_image = result_image
|
236 |
else:
|
237 |
width, height = person_image.size
|
238 |
if show_type == "input & result":
|
|
|
245 |
new_result_image = Image.new("RGB", (width + condition_width + 5, height))
|
246 |
new_result_image.paste(conditions, (0, 0))
|
247 |
new_result_image.paste(result_image, (condition_width + 5, 0))
|
248 |
+
final_image = new_result_image
|
249 |
+
|
250 |
+
# Add watermark
|
251 |
+
watermarked_image = add_watermark(final_image, 'logo.png', 'bottom-right', 5)
|
252 |
+
return watermarked_image
|
253 |
|
254 |
|
255 |
def person_example_fn(image_path):
|