Gopalag commited on
Commit
59a7070
·
verified ·
1 Parent(s): f8d6556

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -111
app.py CHANGED
@@ -16,25 +16,39 @@ pipe = DiffusionPipeline.from_pretrained(
16
  MAX_SEED = np.iinfo(np.int32).max
17
  MAX_IMAGE_SIZE = 2048
18
 
19
- def enhance_prompt_for_pattern(prompt):
20
- """Add specific terms to ensure seamless, tileable patterns."""
21
- pattern_terms = [
22
- "seamless pattern",
23
- "tileable textile design",
24
- "repeating pattern",
25
- "high-quality fabric design",
26
- "continuous pattern",
 
 
 
 
 
 
 
 
27
  ]
28
- enhanced_prompt = f"{prompt}, {random.choice(pattern_terms)}, suitable for textile printing, high-quality fabric design, seamless edges"
 
 
 
 
 
 
29
  return enhanced_prompt
30
 
31
  @spaces.GPU()
32
- def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024,
33
  num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
34
  if randomize_seed:
35
  seed = random.randint(0, MAX_SEED)
36
 
37
- enhanced_prompt = enhance_prompt_for_pattern(prompt)
38
  generator = torch.Generator().manual_seed(seed)
39
  image = pipe(
40
  prompt=enhanced_prompt,
@@ -48,28 +62,33 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024,
48
  return image, seed
49
 
50
  examples = [
51
- "geometric Art Deco shapes in gold and navy",
52
- "delicate floral motifs with small roses and leaves",
53
- "abstract watercolor spots in pastel colors",
54
- "traditional paisley design in earth tones",
55
- "modern minimalist lines and circles",
 
 
 
 
 
 
 
 
56
  ]
57
 
58
- # Enhanced CSS for better visual design and mobile responsiveness
59
  css = """
60
  #col-container {
61
  margin: 0 auto;
62
- max-width: 800px !important;
63
  padding: 20px;
64
  }
65
-
66
  .main-title {
67
  text-align: center;
68
  color: #2d3748;
69
  margin-bottom: 1rem;
70
  font-family: 'Poppins', sans-serif;
71
  }
72
-
73
  .subtitle {
74
  text-align: center;
75
  color: #4a5568;
@@ -78,8 +97,7 @@ css = """
78
  font-size: 0.95rem;
79
  line-height: 1.5;
80
  }
81
-
82
- .pattern-input {
83
  border: 2px solid #e2e8f0;
84
  border-radius: 10px;
85
  padding: 12px !important;
@@ -87,117 +105,74 @@ css = """
87
  font-size: 1rem;
88
  transition: all 0.3s ease;
89
  }
90
-
91
- .pattern-input:focus {
92
- border-color: #4299e1;
93
- box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
94
- }
95
-
96
- .generate-button {
97
- background-color: #4299e1 !important;
98
- color: white !important;
99
- padding: 12px 24px !important;
100
- border-radius: 8px !important;
101
- font-weight: 600 !important;
102
- transition: all 0.3s ease !important;
103
- }
104
-
105
- .generate-button:hover {
106
- background-color: #3182ce !important;
107
- transform: translateY(-1px);
108
- }
109
-
110
- .result-image {
111
- border-radius: 12px;
112
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
113
- margin-top: 1rem;
114
- }
115
-
116
- .advanced-settings {
117
- margin-top: 1.5rem;
118
- border: 1px solid #e2e8f0;
119
- border-radius: 10px;
120
- padding: 1rem;
121
- }
122
-
123
- /* Mobile Responsiveness */
124
- @media (max-width: 768px) {
125
- #col-container {
126
- padding: 12px;
127
- }
128
-
129
- .main-title {
130
- font-size: 1.5rem;
131
- }
132
-
133
- .subtitle {
134
- font-size: 0.9rem;
135
- }
136
-
137
- .pattern-input {
138
- font-size: 0.9rem;
139
- }
140
- }
141
-
142
- /* Custom styling for examples section */
143
- .examples-section {
144
- margin-top: 2rem;
145
- padding: 1rem;
146
- background: #f7fafc;
147
- border-radius: 10px;
148
- }
149
  """
150
 
151
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
152
  with gr.Column(elem_id="col-container"):
153
  gr.Markdown(
154
  """
155
- # 🎨 Deradh's AI Pattern Master
156
  """,
157
  elem_classes=["main-title"]
158
  )
159
 
160
  gr.Markdown(
161
  """
162
- Create beautiful, seamless patterns for your textile designs using AI.
163
- Simply describe your desired pattern, and watch as AI brings your vision to life with
164
- professional-quality, repeatable patterns perfect for fabrics and materials.
165
  """,
166
  elem_classes=["subtitle"]
167
  )
168
 
169
  with gr.Row():
170
- prompt = gr.Text(
171
- label="Pattern Description",
172
- show_label=False,
173
- max_lines=1,
174
- placeholder="Describe your dream pattern (e.g., 'geometric Art Deco shapes in gold and navy')",
175
- container=False,
176
- elem_classes=["pattern-input"]
177
- )
 
 
 
 
 
 
 
 
178
  run_button = gr.Button(
179
  "✨ Generate",
180
  scale=0,
181
  elem_classes=["generate-button"]
182
  )
183
 
184
- result = gr.Image(
185
- label="Your Generated Pattern",
186
- show_label=True,
187
- elem_classes=["result-image"]
188
- )
 
 
 
 
 
 
 
 
189
 
190
  with gr.Accordion("🔧 Advanced Settings", open=False):
191
- with gr.Group(elem_classes=["advanced-settings"]):
192
  seed = gr.Slider(
193
- label="Pattern Seed",
194
  minimum=0,
195
  maximum=MAX_SEED,
196
  step=1,
197
  value=0,
198
  )
199
  randomize_seed = gr.Checkbox(
200
- label="Randomize Pattern",
201
  value=True
202
  )
203
 
@@ -225,20 +200,18 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
225
  value=4,
226
  )
227
 
228
- with gr.Group(elem_classes=["examples-section"]):
229
- gr.Markdown("### 💫 Try These Examples")
230
- gr.Examples(
231
- examples=examples,
232
- fn=infer,
233
- inputs=[prompt],
234
- outputs=[result, seed],
235
- cache_examples="lazy"
236
- )
237
 
238
  gr.on(
239
  triggers=[run_button.click, prompt.submit],
240
  fn=infer,
241
- inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
242
  outputs=[result, seed]
243
  )
244
 
 
16
  MAX_SEED = np.iinfo(np.int32).max
17
  MAX_IMAGE_SIZE = 2048
18
 
19
+ def enhance_prompt_for_tshirt(prompt, style=None):
20
+ """Add specific terms to ensure good t-shirt designs."""
21
+ style_terms = {
22
+ "minimal": ["simple geometric shapes", "clean lines", "minimalist illustration"],
23
+ "vintage": ["distressed effect", "retro typography", "vintage illustration"],
24
+ "artistic": ["hand-drawn style", "watercolor effect", "artistic illustration"],
25
+ "geometric": ["abstract shapes", "geometric patterns", "modern design"],
26
+ "typography": ["bold typography", "creative lettering", "text-based design"]
27
+ }
28
+
29
+ base_terms = [
30
+ "t-shirt design",
31
+ "centered composition",
32
+ "high quality",
33
+ "professional design",
34
+ "clear background"
35
  ]
36
+
37
+ enhanced_prompt = f"{prompt}, {', '.join(base_terms)}"
38
+
39
+ if style and style in style_terms:
40
+ style_specific_terms = style_terms[style]
41
+ enhanced_prompt = f"{enhanced_prompt}, {', '.join(style_specific_terms)}"
42
+
43
  return enhanced_prompt
44
 
45
  @spaces.GPU()
46
+ def infer(prompt, style=None, seed=42, randomize_seed=False, width=1024, height=1024,
47
  num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
48
  if randomize_seed:
49
  seed = random.randint(0, MAX_SEED)
50
 
51
+ enhanced_prompt = enhance_prompt_for_tshirt(prompt, style)
52
  generator = torch.Generator().manual_seed(seed)
53
  image = pipe(
54
  prompt=enhanced_prompt,
 
62
  return image, seed
63
 
64
  examples = [
65
+ ["Cool geometric mountain landscape", "minimal"],
66
+ ["Vintage motorcycle with flames", "vintage"],
67
+ ["Abstract watercolor butterfly", "artistic"],
68
+ ["Sacred geometry mandala", "geometric"],
69
+ ["Adventure Awaits typography", "typography"],
70
+ ]
71
+
72
+ styles = [
73
+ "minimal",
74
+ "vintage",
75
+ "artistic",
76
+ "geometric",
77
+ "typography"
78
  ]
79
 
 
80
  css = """
81
  #col-container {
82
  margin: 0 auto;
83
+ max-width: 1200px !important;
84
  padding: 20px;
85
  }
 
86
  .main-title {
87
  text-align: center;
88
  color: #2d3748;
89
  margin-bottom: 1rem;
90
  font-family: 'Poppins', sans-serif;
91
  }
 
92
  .subtitle {
93
  text-align: center;
94
  color: #4a5568;
 
97
  font-size: 0.95rem;
98
  line-height: 1.5;
99
  }
100
+ .design-input {
 
101
  border: 2px solid #e2e8f0;
102
  border-radius: 10px;
103
  padding: 12px !important;
 
105
  font-size: 1rem;
106
  transition: all 0.3s ease;
107
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  """
109
 
110
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
111
  with gr.Column(elem_id="col-container"):
112
  gr.Markdown(
113
  """
114
+ # 👕 T-Shirt Design Generator
115
  """,
116
  elem_classes=["main-title"]
117
  )
118
 
119
  gr.Markdown(
120
  """
121
+ Create unique t-shirt designs using AI.
122
+ Describe your design idea and select a style to generate professional-quality artwork
123
+ perfect for custom t-shirts.
124
  """,
125
  elem_classes=["subtitle"]
126
  )
127
 
128
  with gr.Row():
129
+ with gr.Column(scale=2):
130
+ prompt = gr.Text(
131
+ label="Design Description",
132
+ show_label=False,
133
+ max_lines=1,
134
+ placeholder="Describe your t-shirt design idea",
135
+ container=False,
136
+ elem_classes=["design-input"]
137
+ )
138
+ with gr.Column(scale=1):
139
+ style = gr.Dropdown(
140
+ choices=[""] + styles,
141
+ value="",
142
+ label="Style",
143
+ container=False
144
+ )
145
  run_button = gr.Button(
146
  "✨ Generate",
147
  scale=0,
148
  elem_classes=["generate-button"]
149
  )
150
 
151
+ with gr.Row():
152
+ with gr.Column():
153
+ result = gr.Image(
154
+ label="Generated Design",
155
+ show_label=True,
156
+ elem_classes=["result-image"]
157
+ )
158
+ with gr.Column():
159
+ preview = gr.Image(
160
+ label="T-Shirt Preview",
161
+ show_label=True,
162
+ elem_classes=["preview-image"]
163
+ )
164
 
165
  with gr.Accordion("🔧 Advanced Settings", open=False):
166
+ with gr.Group():
167
  seed = gr.Slider(
168
+ label="Design Seed",
169
  minimum=0,
170
  maximum=MAX_SEED,
171
  step=1,
172
  value=0,
173
  )
174
  randomize_seed = gr.Checkbox(
175
+ label="Randomize Design",
176
  value=True
177
  )
178
 
 
200
  value=4,
201
  )
202
 
203
+ gr.Examples(
204
+ examples=examples,
205
+ fn=infer,
206
+ inputs=[prompt, style],
207
+ outputs=[result, seed],
208
+ cache_examples=True
209
+ )
 
 
210
 
211
  gr.on(
212
  triggers=[run_button.click, prompt.submit],
213
  fn=infer,
214
+ inputs=[prompt, style, seed, randomize_seed, width, height, num_inference_steps],
215
  outputs=[result, seed]
216
  )
217