Update app.py
Browse files
app.py
CHANGED
@@ -75,281 +75,73 @@ def infer(control_image, prompt, seed=42, randomize_seed=False, width=1024, heig
|
|
75 |
except Exception as e:
|
76 |
return None, f"Error during inference: {str(e)}"
|
77 |
|
78 |
-
|
79 |
-
css = """
|
80 |
-
:root {
|
81 |
-
--primary-color: #6366f1;
|
82 |
-
--secondary-color: #818cf8;
|
83 |
-
--background-color: #1e1b4b;
|
84 |
-
--text-color: #f3f4f6;
|
85 |
-
--card-bg: rgba(30, 27, 75, 0.7);
|
86 |
-
--border-radius: 12px;
|
87 |
-
}
|
88 |
-
|
89 |
-
body {
|
90 |
-
background: var(--background-color);
|
91 |
-
color: var(--text-color);
|
92 |
-
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
93 |
-
}
|
94 |
-
|
95 |
-
/* Animated gradient background */
|
96 |
-
.gradio-container {
|
97 |
-
position: relative;
|
98 |
-
overflow: hidden;
|
99 |
-
}
|
100 |
-
|
101 |
-
.gradio-container::before {
|
102 |
-
content: '';
|
103 |
-
position: fixed;
|
104 |
-
top: 0;
|
105 |
-
left: 0;
|
106 |
-
width: 100vw;
|
107 |
-
height: 100vh;
|
108 |
-
background: linear-gradient(
|
109 |
-
45deg,
|
110 |
-
var(--background-color),
|
111 |
-
var(--primary-color),
|
112 |
-
var(--secondary-color)
|
113 |
-
);
|
114 |
-
animation: gradient 15s ease infinite;
|
115 |
-
background-size: 400% 400%;
|
116 |
-
z-index: -1;
|
117 |
-
opacity: 0.3;
|
118 |
-
}
|
119 |
-
|
120 |
-
@keyframes gradient {
|
121 |
-
0% { background-position: 0% 50%; }
|
122 |
-
50% { background-position: 100% 50%; }
|
123 |
-
100% { background-position: 0% 50%; }
|
124 |
-
}
|
125 |
-
|
126 |
-
/* Noise overlay */
|
127 |
-
.gradio-container::after {
|
128 |
-
content: '';
|
129 |
-
position: fixed;
|
130 |
-
top: 0;
|
131 |
-
left: 0;
|
132 |
-
width: 100vw;
|
133 |
-
height: 100vh;
|
134 |
-
background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
|
135 |
-
opacity: 0.05;
|
136 |
-
z-index: -1;
|
137 |
-
pointer-events: none;
|
138 |
-
}
|
139 |
-
|
140 |
#col-container {
|
141 |
-
|
142 |
-
|
143 |
-
padding: 2rem;
|
144 |
-
background: var(--card-bg);
|
145 |
-
backdrop-filter: blur(10px);
|
146 |
-
border-radius: var(--border-radius);
|
147 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
148 |
-
}
|
149 |
-
|
150 |
-
/* Typography */
|
151 |
-
#col-container h1 {
|
152 |
-
color: var(--text-color);
|
153 |
-
font-size: 2.5rem;
|
154 |
-
margin-bottom: 1.5rem;
|
155 |
-
text-align: center;
|
156 |
-
font-weight: 700;
|
157 |
-
}
|
158 |
-
|
159 |
-
#col-container a {
|
160 |
-
color: var(--primary-color);
|
161 |
-
text-decoration: none;
|
162 |
-
transition: color 0.3s ease;
|
163 |
-
}
|
164 |
-
|
165 |
-
#col-container a:hover {
|
166 |
-
color: var(--secondary-color);
|
167 |
-
}
|
168 |
-
|
169 |
-
/* Input elements styling */
|
170 |
-
.input-container {
|
171 |
-
background: rgba(255, 255, 255, 0.05);
|
172 |
-
padding: 1.5rem;
|
173 |
-
border-radius: var(--border-radius);
|
174 |
-
margin-bottom: 1.5rem;
|
175 |
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
176 |
-
transition: all 0.3s ease;
|
177 |
-
}
|
178 |
-
|
179 |
-
.input-container:hover {
|
180 |
-
background: rgba(255, 255, 255, 0.08);
|
181 |
-
border-color: rgba(255, 255, 255, 0.2);
|
182 |
-
}
|
183 |
-
|
184 |
-
/* Button styling */
|
185 |
-
button.primary {
|
186 |
-
background: var(--primary-color) !important;
|
187 |
-
border: none !important;
|
188 |
-
padding: 0.75rem 1.5rem !important;
|
189 |
-
border-radius: var(--border-radius) !important;
|
190 |
-
color: white !important;
|
191 |
-
font-weight: 600 !important;
|
192 |
-
transition: all 0.3s ease !important;
|
193 |
-
text-transform: uppercase;
|
194 |
-
letter-spacing: 0.5px;
|
195 |
-
}
|
196 |
-
|
197 |
-
button.primary:hover {
|
198 |
-
background: var(--secondary-color) !important;
|
199 |
-
transform: translateY(-2px);
|
200 |
-
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
|
201 |
-
}
|
202 |
-
|
203 |
-
/* Slider styling */
|
204 |
-
.gr-slider {
|
205 |
-
--slider-color: var(--primary-color) !important;
|
206 |
-
}
|
207 |
-
|
208 |
-
.gr-slider .handle {
|
209 |
-
background: var(--primary-color) !important;
|
210 |
-
border: 2px solid white !important;
|
211 |
-
}
|
212 |
-
|
213 |
-
/* Image upload area styling */
|
214 |
-
.image-upload-box {
|
215 |
-
border: 2px dashed rgba(255, 255, 255, 0.2);
|
216 |
-
border-radius: var(--border-radius);
|
217 |
-
padding: 2rem;
|
218 |
-
text-align: center;
|
219 |
-
transition: all 0.3s ease;
|
220 |
-
background: rgba(255, 255, 255, 0.03);
|
221 |
-
}
|
222 |
-
|
223 |
-
.image-upload-box:hover {
|
224 |
-
border-color: var(--primary-color);
|
225 |
-
background: rgba(255, 255, 255, 0.05);
|
226 |
-
cursor: pointer;
|
227 |
-
}
|
228 |
-
|
229 |
-
/* Results area styling */
|
230 |
-
.results-container {
|
231 |
-
background: rgba(255, 255, 255, 0.05);
|
232 |
-
padding: 1.5rem;
|
233 |
-
border-radius: var(--border-radius);
|
234 |
-
margin-top: 1.5rem;
|
235 |
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
236 |
-
}
|
237 |
-
|
238 |
-
/* Accordion styling */
|
239 |
-
.gr-accordion {
|
240 |
-
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
241 |
-
border-radius: var(--border-radius) !important;
|
242 |
-
background: rgba(255, 255, 255, 0.05) !important;
|
243 |
-
transition: all 0.3s ease;
|
244 |
-
}
|
245 |
-
|
246 |
-
.gr-accordion:hover {
|
247 |
-
background: rgba(255, 255, 255, 0.08) !important;
|
248 |
-
}
|
249 |
-
|
250 |
-
.gr-accordion-title {
|
251 |
-
color: var(--text-color) !important;
|
252 |
-
font-weight: 600 !important;
|
253 |
-
}
|
254 |
-
|
255 |
-
/* Form elements */
|
256 |
-
input[type="text"],
|
257 |
-
input[type="number"],
|
258 |
-
textarea {
|
259 |
-
background: rgba(255, 255, 255, 0.05) !important;
|
260 |
-
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
261 |
-
border-radius: var(--border-radius) !important;
|
262 |
-
color: var(--text-color) !important;
|
263 |
-
transition: all 0.3s ease !important;
|
264 |
-
}
|
265 |
-
|
266 |
-
input[type="text"]:focus,
|
267 |
-
input[type="number"]:focus,
|
268 |
-
textarea:focus {
|
269 |
-
background: rgba(255, 255, 255, 0.08) !important;
|
270 |
-
border-color: var(--primary-color) !important;
|
271 |
-
outline: none !important;
|
272 |
-
}
|
273 |
-
|
274 |
-
/* Checkbox styling */
|
275 |
-
input[type="checkbox"] {
|
276 |
-
accent-color: var(--primary-color);
|
277 |
-
width: 1.2em;
|
278 |
-
height: 1.2em;
|
279 |
}
|
280 |
"""
|
281 |
|
282 |
-
# Gradio UI Layout
|
283 |
with gr.Blocks(css=css) as demo:
|
|
|
284 |
with gr.Column(elem_id="col-container"):
|
285 |
-
gr.Markdown("""# FLUX.1 Depth [dev] with LoRA Support
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
lora_status = gr.Textbox(label="LoRA Status", interactive=False)
|
300 |
-
|
301 |
-
# Image upload and prompt in styled containers
|
302 |
-
with gr.Box(elem_classes="input-container"):
|
303 |
-
control_image = gr.Image(
|
304 |
-
label="Upload Control Image",
|
305 |
-
type="pil",
|
306 |
-
elem_classes="image-upload-box"
|
307 |
)
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
show_label=True
|
314 |
-
)
|
315 |
-
run_button = gr.Button("Generate", elem_classes="primary", scale=0)
|
316 |
-
|
317 |
-
# Results area
|
318 |
-
with gr.Box(elem_classes="results-container"):
|
319 |
-
result = gr.Image(label="Generated Result")
|
320 |
-
error_message = gr.Textbox(label="Error", visible=False)
|
321 |
-
|
322 |
-
# Advanced settings in styled accordion
|
323 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
with gr.Row():
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
)
|
333 |
-
randomize_seed = gr.Checkbox(
|
334 |
-
label="Randomize seed",
|
335 |
-
value=True
|
336 |
-
)
|
337 |
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
)
|
346 |
-
height = gr.Slider(
|
347 |
-
label="Height",
|
348 |
-
minimum=256,
|
349 |
-
maximum=MAX_IMAGE_SIZE,
|
350 |
-
step=32,
|
351 |
-
value=1024
|
352 |
-
)
|
353 |
|
354 |
with gr.Row():
|
355 |
guidance_scale = gr.Slider(
|
@@ -357,14 +149,15 @@ with gr.Blocks(css=css) as demo:
|
|
357 |
minimum=1,
|
358 |
maximum=30,
|
359 |
step=0.5,
|
360 |
-
value=10
|
361 |
)
|
|
|
362 |
num_inference_steps = gr.Slider(
|
363 |
label="Number of inference steps",
|
364 |
minimum=1,
|
365 |
maximum=50,
|
366 |
step=1,
|
367 |
-
value=28
|
368 |
)
|
369 |
|
370 |
# Event handlers
|
|
|
75 |
except Exception as e:
|
76 |
return None, f"Error during inference: {str(e)}"
|
77 |
|
78 |
+
css="""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
#col-container {
|
80 |
+
margin: 0 auto;
|
81 |
+
max-width: 520px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
83 |
"""
|
84 |
|
|
|
85 |
with gr.Blocks(css=css) as demo:
|
86 |
+
|
87 |
with gr.Column(elem_id="col-container"):
|
88 |
+
gr.Markdown(f"""# FLUX.1 Depth [dev] with LoRA Support
|
89 |
+
12B param rectified flow transformer structural conditioning tuned, guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
90 |
+
[[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
91 |
+
""")
|
92 |
+
|
93 |
+
# LoRA controls
|
94 |
+
with gr.Row():
|
95 |
+
lora_path = gr.Textbox(
|
96 |
+
label="HuggingFace LoRA Path",
|
97 |
+
placeholder="e.g., Borcherding/FLUX.1-dev-LoRA-AutumnSpringTrees"
|
98 |
+
)
|
99 |
+
load_lora_btn = gr.Button("Load LoRA")
|
100 |
+
unload_lora_btn = gr.Button("Unload LoRA")
|
101 |
|
102 |
+
lora_status = gr.Textbox(label="LoRA Status", interactive=False)
|
103 |
+
|
104 |
+
control_image = gr.Image(label="Upload the image for control", type="pil")
|
105 |
+
with gr.Row():
|
106 |
+
prompt = gr.Text(
|
107 |
+
label="Prompt",
|
108 |
+
show_label=False,
|
109 |
+
max_lines=1,
|
110 |
+
placeholder="Enter your prompt",
|
111 |
+
container=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
)
|
113 |
+
run_button = gr.Button("Run", scale=0)
|
114 |
+
|
115 |
+
result = gr.Image(label="Result", show_label=False)
|
116 |
+
error_message = gr.Textbox(label="Error", visible=False)
|
117 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
with gr.Accordion("Advanced Settings", open=False):
|
119 |
+
seed = gr.Slider(
|
120 |
+
label="Seed",
|
121 |
+
minimum=0,
|
122 |
+
maximum=MAX_SEED,
|
123 |
+
step=1,
|
124 |
+
value=0,
|
125 |
+
)
|
126 |
+
|
127 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
128 |
+
|
129 |
with gr.Row():
|
130 |
+
width = gr.Slider(
|
131 |
+
label="Width",
|
132 |
+
minimum=256,
|
133 |
+
maximum=MAX_IMAGE_SIZE,
|
134 |
+
step=32,
|
135 |
+
value=1024,
|
136 |
+
)
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
+
height = gr.Slider(
|
139 |
+
label="Height",
|
140 |
+
minimum=256,
|
141 |
+
maximum=MAX_IMAGE_SIZE,
|
142 |
+
step=32,
|
143 |
+
value=1024,
|
144 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
with gr.Row():
|
147 |
guidance_scale = gr.Slider(
|
|
|
149 |
minimum=1,
|
150 |
maximum=30,
|
151 |
step=0.5,
|
152 |
+
value=10,
|
153 |
)
|
154 |
+
|
155 |
num_inference_steps = gr.Slider(
|
156 |
label="Number of inference steps",
|
157 |
minimum=1,
|
158 |
maximum=50,
|
159 |
step=1,
|
160 |
+
value=28,
|
161 |
)
|
162 |
|
163 |
# Event handlers
|