Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -59,6 +59,33 @@ def enhance_prompt_for_pattern(prompt, style, fabric):
|
|
59 |
enhanced_prompt += ", suitable for textile printing, high-quality fabric design, seamless edges"
|
60 |
return enhanced_prompt
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
def create_fabric_preview(image):
|
63 |
"""Create a fabric preview by tiling the pattern."""
|
64 |
# Create a 4x2 grid of the pattern
|
@@ -69,6 +96,8 @@ def create_fabric_preview(image):
|
|
69 |
for x in range(4):
|
70 |
preview.paste(image, (x * width, y * height))
|
71 |
|
|
|
|
|
72 |
return preview
|
73 |
|
74 |
@spaces.GPU()
|
@@ -88,10 +117,18 @@ def infer(prompt, style, fabric, seed=42, randomize_seed=False, width=1024, heig
|
|
88 |
guidance_scale=0.0
|
89 |
).images[0]
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
# Create fabric preview
|
92 |
-
fabric_preview = create_fabric_preview(
|
93 |
|
94 |
-
return
|
95 |
|
96 |
examples = [
|
97 |
["geometric Art Deco shapes in gold and navy", "Geometric", "None"],
|
@@ -194,7 +231,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
|
194 |
with gr.Column(elem_id="col-container"):
|
195 |
gr.Markdown(
|
196 |
"""
|
197 |
-
# 🎨
|
198 |
""",
|
199 |
elem_classes=["main-title"]
|
200 |
)
|
|
|
59 |
enhanced_prompt += ", suitable for textile printing, high-quality fabric design, seamless edges"
|
60 |
return enhanced_prompt
|
61 |
|
62 |
+
def add_logo(image):
|
63 |
+
"""Add logo to the bottom right corner of the image."""
|
64 |
+
try:
|
65 |
+
logo = Image.open('logo.png')
|
66 |
+
# Resize logo to be proportional to image size (e.g., 10% of image width)
|
67 |
+
logo_width = image.size[0] // 10
|
68 |
+
logo_ratio = logo.size[1] / logo.size[0]
|
69 |
+
logo_height = int(logo_width * logo_ratio)
|
70 |
+
logo = logo.resize((logo_width, logo_height), Image.Resampling.LANCZOS)
|
71 |
+
|
72 |
+
# If logo has alpha channel, create a copy of the image to paste onto
|
73 |
+
if logo.mode == 'RGBA':
|
74 |
+
temp_img = image.copy()
|
75 |
+
# Calculate position for bottom right corner with small padding
|
76 |
+
position = (image.size[0] - logo_width - 20, image.size[1] - logo_height - 20)
|
77 |
+
temp_img.paste(logo, position, logo)
|
78 |
+
return temp_img
|
79 |
+
else:
|
80 |
+
# For non-transparent logos
|
81 |
+
temp_img = image.copy()
|
82 |
+
position = (image.size[0] - logo_width - 20, image.size[1] - logo_height - 20)
|
83 |
+
temp_img.paste(logo, position)
|
84 |
+
return temp_img
|
85 |
+
except Exception as e:
|
86 |
+
print(f"Error adding logo: {e}")
|
87 |
+
return image
|
88 |
+
|
89 |
def create_fabric_preview(image):
|
90 |
"""Create a fabric preview by tiling the pattern."""
|
91 |
# Create a 4x2 grid of the pattern
|
|
|
96 |
for x in range(4):
|
97 |
preview.paste(image, (x * width, y * height))
|
98 |
|
99 |
+
# Add logo to the preview
|
100 |
+
preview = add_logo(preview)
|
101 |
return preview
|
102 |
|
103 |
@spaces.GPU()
|
|
|
117 |
guidance_scale=0.0
|
118 |
).images[0]
|
119 |
|
120 |
+
# Convert to PIL Image for processing
|
121 |
+
pil_image = image
|
122 |
+
if not isinstance(image, Image.Image):
|
123 |
+
pil_image = Image.fromarray(np.uint8(image))
|
124 |
+
|
125 |
+
# Add logo to single pattern
|
126 |
+
pattern_with_logo = add_logo(pil_image)
|
127 |
+
|
128 |
# Create fabric preview
|
129 |
+
fabric_preview = create_fabric_preview(pil_image)
|
130 |
|
131 |
+
return pattern_with_logo, fabric_preview, seed
|
132 |
|
133 |
examples = [
|
134 |
["geometric Art Deco shapes in gold and navy", "Geometric", "None"],
|
|
|
231 |
with gr.Column(elem_id="col-container"):
|
232 |
gr.Markdown(
|
233 |
"""
|
234 |
+
# 🎨 Professional Textile Pattern Generator
|
235 |
""",
|
236 |
elem_classes=["main-title"]
|
237 |
)
|