Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ from diffusers import DiffusionPipeline
|
|
8 |
dtype = torch.bfloat16
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
-
# Initialize the model
|
12 |
pipe = DiffusionPipeline.from_pretrained(
|
13 |
"black-forest-labs/FLUX.1-schnell",
|
14 |
torch_dtype=dtype
|
@@ -17,7 +16,6 @@ pipe = DiffusionPipeline.from_pretrained(
|
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
MAX_IMAGE_SIZE = 2048
|
19 |
|
20 |
-
# Pattern-specific prompt engineering
|
21 |
def enhance_prompt_for_pattern(prompt):
|
22 |
"""Add specific terms to ensure seamless, tileable patterns."""
|
23 |
pattern_terms = [
|
@@ -36,9 +34,7 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024,
|
|
36 |
if randomize_seed:
|
37 |
seed = random.randint(0, MAX_SEED)
|
38 |
|
39 |
-
# Enhance the prompt for pattern generation
|
40 |
enhanced_prompt = enhance_prompt_for_pattern(prompt)
|
41 |
-
|
42 |
generator = torch.Generator().manual_seed(seed)
|
43 |
image = pipe(
|
44 |
prompt=enhanced_prompt,
|
@@ -51,7 +47,6 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024,
|
|
51 |
|
52 |
return image, seed
|
53 |
|
54 |
-
# Example prompts specifically for pattern generation
|
55 |
examples = [
|
56 |
"geometric Art Deco shapes in gold and navy",
|
57 |
"delicate floral motifs with small roses and leaves",
|
@@ -60,77 +55,185 @@ examples = [
|
|
60 |
"modern minimalist lines and circles",
|
61 |
]
|
62 |
|
|
|
63 |
css = """
|
64 |
#col-container {
|
65 |
margin: 0 auto;
|
66 |
-
max-width:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
"""
|
69 |
|
70 |
-
with gr.Blocks(css=css) as demo:
|
71 |
with gr.Column(elem_id="col-container"):
|
72 |
-
gr.Markdown(
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
with gr.Row():
|
81 |
prompt = gr.Text(
|
82 |
label="Pattern Description",
|
83 |
show_label=False,
|
84 |
max_lines=1,
|
85 |
-
placeholder="Describe your
|
86 |
container=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
)
|
88 |
-
run_button = gr.Button("Generate Pattern", scale=0)
|
89 |
|
90 |
-
result = gr.Image(
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
with gr.Accordion("Advanced Settings", open=False):
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
width = gr.Slider(
|
104 |
-
label="Width",
|
105 |
-
minimum=256,
|
106 |
-
maximum=MAX_IMAGE_SIZE,
|
107 |
-
step=32,
|
108 |
-
value=1024,
|
109 |
)
|
110 |
-
|
111 |
-
label="
|
112 |
-
|
113 |
-
maximum=MAX_IMAGE_SIZE,
|
114 |
-
step=32,
|
115 |
-
value=1024,
|
116 |
)
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
num_inference_steps = gr.Slider(
|
120 |
-
label="
|
121 |
minimum=1,
|
122 |
maximum=50,
|
123 |
step=1,
|
124 |
value=4,
|
125 |
)
|
126 |
|
127 |
-
gr.
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
134 |
|
135 |
gr.on(
|
136 |
triggers=[run_button.click, prompt.submit],
|
|
|
8 |
dtype = torch.bfloat16
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
|
|
11 |
pipe = DiffusionPipeline.from_pretrained(
|
12 |
"black-forest-labs/FLUX.1-schnell",
|
13 |
torch_dtype=dtype
|
|
|
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 = [
|
|
|
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,
|
|
|
47 |
|
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",
|
|
|
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;
|
76 |
+
margin-bottom: 2rem;
|
77 |
+
font-family: 'Inter', sans-serif;
|
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;
|
86 |
+
margin-bottom: 1rem !important;
|
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 |
+
|
204 |
+
with gr.Row():
|
205 |
+
width = gr.Slider(
|
206 |
+
label="Width",
|
207 |
+
minimum=256,
|
208 |
+
maximum=MAX_IMAGE_SIZE,
|
209 |
+
step=32,
|
210 |
+
value=1024,
|
211 |
+
)
|
212 |
+
height = gr.Slider(
|
213 |
+
label="Height",
|
214 |
+
minimum=256,
|
215 |
+
maximum=MAX_IMAGE_SIZE,
|
216 |
+
step=32,
|
217 |
+
value=1024,
|
218 |
+
)
|
219 |
+
|
220 |
num_inference_steps = gr.Slider(
|
221 |
+
label="Generation Quality (Steps)",
|
222 |
minimum=1,
|
223 |
maximum=50,
|
224 |
step=1,
|
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],
|