openfree commited on
Commit
06b6264
·
verified ·
1 Parent(s): d3fa7c4

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +321 -80
app-backup.py CHANGED
@@ -152,88 +152,345 @@ def generate_image(
152
  return image, debug_images, seed
153
 
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  _HEADER_ = '''
156
- <div style="text-align: center; max-width: 650px; margin: 0 auto;">
157
- <h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">DreamO Video</h1>
158
- <p style="font-size: 1rem; margin-bottom: 1.5rem;">Paper: <a href='https://arxiv.org/abs/2504.16915' target='_blank'>DreamO: A Unified Framework for Image Customization</a> | Codes: <a href='https://github.com/bytedance/DreamO' target='_blank'>GitHub</a></p>
 
 
 
 
 
 
159
  </div>
160
 
161
- 🚩 Update Notes:
162
- - 2025.05.11: We have updated the model to mitigate over-saturation and plastic-face issues. The new version shows consistent improvements over the previous release.
163
- - 2025.05.13: 'DreamO Video' Integration version Release
 
 
 
 
164
  '''
165
 
166
  _CITE_ = r"""
167
- If DreamO is helpful, please help to the <a href='https://discord.gg/openfreeai' target='_blank'> community</a>. Thanks!
168
- ---
169
-
170
- 📧 **Contact**
171
- If you have any questions or feedbacks, feel free to open a discussion or contact <b>[email protected]</b>
 
172
  """
173
 
174
  def create_demo():
175
-
176
- with gr.Blocks(theme="apriel") as demo:
177
- gr.Markdown(_HEADER_)
178
 
179
  with gr.Row():
180
- with gr.Column():
181
- with gr.Row():
182
- ref_image1 = gr.Image(label="ref image 1", type="numpy", height=256)
183
- ref_image2 = gr.Image(label="ref image 2", type="numpy", height=256)
184
- with gr.Row():
185
- ref_task1 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="task for ref image 1")
186
- ref_task2 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="task for ref image 2")
187
- prompt = gr.Textbox(label="Prompt", value="a person playing guitar in the street")
188
- width = gr.Slider(768, 1024, 1024, step=16, label="Width")
189
- height = gr.Slider(768, 1024, 1024, step=16, label="Height")
190
- num_steps = gr.Slider(8, 30, 12, step=1, label="Number of steps")
191
- guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Guidance")
192
- seed = gr.Textbox(label="Seed (-1 for random)", value="-1")
193
- with gr.Accordion("Advanced Options", open=False, visible=False):
194
- ref_res = gr.Slider(512, 1024, 512, step=16, label="resolution for ref image")
195
- neg_prompt = gr.Textbox(label="Neg Prompt", value="")
196
- neg_guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Neg Guidance")
197
- true_cfg = gr.Slider(1, 5, 1, step=0.1, label="true cfg")
198
- cfg_start_step = gr.Slider(0, 30, 0, step=1, label="cfg start step")
199
- cfg_end_step = gr.Slider(0, 30, 0, step=1, label="cfg end step")
200
- first_step_guidance = gr.Slider(0, 10, 0, step=0.1, label="first step guidance")
201
- generate_btn = gr.Button("Generate")
202
- gr.Markdown(_CITE_)
203
-
204
- with gr.Column():
205
- output_image = gr.Image(label="Generated Image", format='png')
206
- debug_image = gr.Gallery(
207
- label="Preprocessing output (including possible face crop and background remove)",
208
- elem_id="gallery",
209
- )
210
- seed_output = gr.Textbox(label="Used Seed")
211
-
212
- with gr.Row(), gr.Column():
213
- gr.Markdown("## Examples")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  example_inps = [
215
  [
216
- 'example_inputs/woman1.png',
217
- None,
218
- 'ip',
219
- 'ip',
220
- 'profile shot dark photo of a 25-year-old female with smoke escaping from her mouth, the backlit smoke gives the image an ephemeral quality, natural face, natural eyebrows, natural skin texture, award winning photo, highly detailed face, atmospheric lighting, film grain, monochrome', # noqa E501
221
- 9180879731249039735,
222
- ],
223
- [
224
- 'example_inputs/man1.png',
225
  None,
226
  'ip',
227
  'ip',
228
- 'a man sitting on the cloud, playing guitar',
229
  1206523688721442817,
230
  ],
231
  [
232
  'example_inputs/toy1.png',
233
  None,
 
234
  'ip',
235
- 'ip',
236
- 'a purple toy holding a sign saying "DreamO", on the mountain',
237
  10441727852953907380,
238
  ],
239
  [
@@ -245,11 +502,11 @@ def create_demo():
245
  116150031980664704,
246
  ],
247
  [
248
- 'example_inputs/hinton.jpeg',
249
  None,
250
  'id',
251
  'ip',
252
- 'portrait, Chibi',
253
  5443415087540486371,
254
  ],
255
  [
@@ -292,27 +549,11 @@ def create_demo():
292
  'two dogs in the jungle',
293
  6187006025405083344,
294
  ],
295
- [
296
- 'example_inputs/woman3.png',
297
- 'example_inputs/cat.png',
298
- 'ip',
299
- 'ip',
300
- 'A girl rides a giant cat, walking in the noisy modern city. High definition, realistic, non-cartoonish. Excellent photography work, 8k high definition.', # noqa E501
301
- 11980469406460273604,
302
- ],
303
- [
304
- 'example_inputs/man2.jpeg',
305
- 'example_inputs/woman4.jpeg',
306
- 'ip',
307
- 'ip',
308
- 'a man is dancing with a woman in the room',
309
- 8303780338601106219,
310
- ],
311
  ]
312
  gr.Examples(
313
  examples=example_inps,
314
  inputs=[ref_image1, ref_image2, ref_task1, ref_task2, prompt, seed],
315
- label='row 1-4: IP task; row 5: ID task; row 6-7: Style task. row 8-9: Try-On task; row 10-12: Multi IP',
316
  cache_examples='lazy',
317
  outputs=[output_image, debug_image, seed_output],
318
  fn=generate_image,
@@ -347,4 +588,4 @@ def create_demo():
347
 
348
  if __name__ == '__main__':
349
  demo = create_demo()
350
- demo.launch()
 
152
  return image, debug_images, seed
153
 
154
 
155
+ # Custom CSS for pastel theme
156
+ _CUSTOM_CSS_ = """
157
+ :root {
158
+ --primary-color: #f8c3cd; /* Sakura pink - primary accent */
159
+ --secondary-color: #b3e5fc; /* Pastel blue - secondary accent */
160
+ --background-color: #f5f5f7; /* Very light gray background */
161
+ --card-background: #ffffff; /* White for cards */
162
+ --text-color: #424242; /* Dark gray for text */
163
+ --accent-color: #ffb6c1; /* Light pink for accents */
164
+ --success-color: #c8e6c9; /* Pastel green for success */
165
+ --warning-color: #fff9c4; /* Pastel yellow for warnings */
166
+ --shadow-color: rgba(0, 0, 0, 0.1); /* Shadow color */
167
+ --border-radius: 12px; /* Rounded corners */
168
+ }
169
+
170
+ body {
171
+ background-color: var(--background-color) !important;
172
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
173
+ }
174
+
175
+ .gradio-container {
176
+ max-width: 1200px !important;
177
+ margin: 0 auto !important;
178
+ }
179
+
180
+ /* Header styling */
181
+ h1 {
182
+ color: #9c27b0 !important;
183
+ font-weight: 800 !important;
184
+ text-shadow: 2px 2px 4px rgba(156, 39, 176, 0.2) !important;
185
+ letter-spacing: -0.5px !important;
186
+ }
187
+
188
+ /* Card styling for panels */
189
+ .panel-box {
190
+ border-radius: var(--border-radius) !important;
191
+ box-shadow: 0 8px 16px var(--shadow-color) !important;
192
+ background-color: var(--card-background) !important;
193
+ border: none !important;
194
+ overflow: hidden !important;
195
+ padding: 20px !important;
196
+ margin-bottom: 20px !important;
197
+ }
198
+
199
+ /* Button styling */
200
+ button.gr-button {
201
+ background: linear-gradient(135deg, var(--primary-color), #e1bee7) !important;
202
+ border-radius: var(--border-radius) !important;
203
+ color: #4a148c !important;
204
+ font-weight: 600 !important;
205
+ border: none !important;
206
+ padding: 10px 20px !important;
207
+ transition: all 0.3s ease !important;
208
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
209
+ }
210
+
211
+ button.gr-button:hover {
212
+ transform: translateY(-2px) !important;
213
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15) !important;
214
+ background: linear-gradient(135deg, #e1bee7, var(--primary-color)) !important;
215
+ }
216
+
217
+ /* Input fields styling */
218
+ input, select, textarea, .gr-input {
219
+ border-radius: 8px !important;
220
+ border: 2px solid #e0e0e0 !important;
221
+ padding: 10px 15px !important;
222
+ transition: all 0.3s ease !important;
223
+ background-color: #fafafa !important;
224
+ }
225
+
226
+ input:focus, select:focus, textarea:focus, .gr-input:focus {
227
+ border-color: var(--primary-color) !important;
228
+ box-shadow: 0 0 0 3px rgba(248, 195, 205, 0.3) !important;
229
+ }
230
+
231
+ /* Slider styling */
232
+ .gr-form input[type=range] {
233
+ appearance: none !important;
234
+ width: 100% !important;
235
+ height: 6px !important;
236
+ background: #e0e0e0 !important;
237
+ border-radius: 5px !important;
238
+ outline: none !important;
239
+ }
240
+
241
+ .gr-form input[type=range]::-webkit-slider-thumb {
242
+ appearance: none !important;
243
+ width: 16px !important;
244
+ height: 16px !important;
245
+ background: var(--primary-color) !important;
246
+ border-radius: 50% !important;
247
+ cursor: pointer !important;
248
+ border: 2px solid white !important;
249
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
250
+ }
251
+
252
+ /* Dropdown styling */
253
+ .gr-form select {
254
+ background-color: white !important;
255
+ border: 2px solid #e0e0e0 !important;
256
+ border-radius: 8px !important;
257
+ padding: 10px 15px !important;
258
+ }
259
+
260
+ .gr-form select option {
261
+ padding: 10px !important;
262
+ }
263
+
264
+ /* Image upload area */
265
+ .gr-image-input {
266
+ border: 2px dashed #b39ddb !important;
267
+ border-radius: var(--border-radius) !important;
268
+ background-color: #f3e5f5 !important;
269
+ padding: 20px !important;
270
+ display: flex !important;
271
+ flex-direction: column !important;
272
+ align-items: center !important;
273
+ justify-content: center !important;
274
+ transition: all 0.3s ease !important;
275
+ }
276
+
277
+ .gr-image-input:hover {
278
+ background-color: #ede7f6 !important;
279
+ border-color: #9575cd !important;
280
+ }
281
+
282
+ /* Add a nice pattern to the background */
283
+ body::before {
284
+ content: "" !important;
285
+ position: fixed !important;
286
+ top: 0 !important;
287
+ left: 0 !important;
288
+ width: 100% !important;
289
+ height: 100% !important;
290
+ background:
291
+ radial-gradient(circle at 10% 20%, rgba(248, 195, 205, 0.1) 0%, rgba(245, 245, 247, 0) 20%),
292
+ radial-gradient(circle at 80% 70%, rgba(179, 229, 252, 0.1) 0%, rgba(245, 245, 247, 0) 20%) !important;
293
+ pointer-events: none !important;
294
+ z-index: -1 !important;
295
+ }
296
+
297
+ /* Gallery styling */
298
+ .gr-gallery {
299
+ grid-gap: 15px !important;
300
+ }
301
+
302
+ .gr-gallery-item {
303
+ border-radius: var(--border-radius) !important;
304
+ overflow: hidden !important;
305
+ box-shadow: 0 4px 8px var(--shadow-color) !important;
306
+ transition: transform 0.3s ease !important;
307
+ }
308
+
309
+ .gr-gallery-item:hover {
310
+ transform: scale(1.02) !important;
311
+ }
312
+
313
+ /* Label styling */
314
+ .gr-form label {
315
+ font-weight: 600 !important;
316
+ color: #673ab7 !important;
317
+ margin-bottom: 5px !important;
318
+ }
319
+
320
+ /* Improve spacing */
321
+ .gr-padded {
322
+ padding: 20px !important;
323
+ }
324
+
325
+ .gr-compact {
326
+ gap: 15px !important;
327
+ }
328
+
329
+ .gr-form > div {
330
+ margin-bottom: 16px !important;
331
+ }
332
+
333
+ /* Headings */
334
+ .gr-form h3 {
335
+ color: #7b1fa2 !important;
336
+ margin-top: 5px !important;
337
+ margin-bottom: 15px !important;
338
+ border-bottom: 2px solid #e1bee7 !important;
339
+ padding-bottom: 8px !important;
340
+ }
341
+
342
+ /* Examples section */
343
+ #examples-panel {
344
+ background-color: #f3e5f5 !important;
345
+ border-radius: var(--border-radius) !important;
346
+ padding: 15px !important;
347
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05) !important;
348
+ }
349
+
350
+ #examples-panel h2 {
351
+ color: #7b1fa2 !important;
352
+ font-size: 1.5rem !important;
353
+ margin-bottom: 15px !important;
354
+ }
355
+
356
+ /* Accordion styling */
357
+ .gr-accordion {
358
+ border: 1px solid #e0e0e0 !important;
359
+ border-radius: var(--border-radius) !important;
360
+ overflow: hidden !important;
361
+ }
362
+
363
+ .gr-accordion summary {
364
+ padding: 12px 16px !important;
365
+ background-color: #f9f9f9 !important;
366
+ cursor: pointer !important;
367
+ font-weight: 600 !important;
368
+ color: #673ab7 !important;
369
+ }
370
+
371
+ /* Generate button special styling */
372
+ #generate-btn {
373
+ background: linear-gradient(135deg, #ff9a9e, #fad0c4) !important;
374
+ font-size: 1.1rem !important;
375
+ padding: 12px 24px !important;
376
+ margin-top: 10px !important;
377
+ margin-bottom: 15px !important;
378
+ width: 100% !important;
379
+ }
380
+
381
+ #generate-btn:hover {
382
+ background: linear-gradient(135deg, #fad0c4, #ff9a9e) !important;
383
+ }
384
+ """
385
+
386
  _HEADER_ = '''
387
+ <div style="text-align: center; max-width: 850px; margin: 0 auto; padding: 25px 0;">
388
+ <div style="background: linear-gradient(135deg, #f8c3cd, #e1bee7, #b3e5fc); color: white; padding: 15px; border-radius: 15px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); margin-bottom: 20px;">
389
+ <h1 style="font-size: 3rem; font-weight: 800; margin: 0; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.2);">✨ DreamO Video ✨</h1>
390
+ <p style="font-size: 1.2rem; margin: 10px 0 0;">Create customized images with advanced AI</p>
391
+ </div>
392
+ <div style="background: white; padding: 15px; border-radius: 12px; box-shadow: 0 5px 15px rgba(0,0,0,0.05);">
393
+ <p style="font-size: 1rem; margin: 0;">Paper: <a href='https://arxiv.org/abs/2504.16915' target='_blank' style="color: #9c27b0; font-weight: 600;">DreamO: A Unified Framework for Image Customization</a> |
394
+ Codes: <a href='https://github.com/bytedance/DreamO' target='_blank' style="color: #9c27b0; font-weight: 600;">GitHub</a></p>
395
+ </div>
396
  </div>
397
 
398
+ <div style="background: #fff9c4; padding: 15px; border-radius: 12px; margin-bottom: 20px; border-left: 5px solid #ffd54f; box-shadow: 0 5px 15px rgba(0,0,0,0.05);">
399
+ <h3 style="margin-top: 0; color: #ff6f00;">🚩 Update Notes:</h3>
400
+ <ul style="margin-bottom: 0; padding-left: 20px;">
401
+ <li><b>2025.05.11:</b> We have updated the model to mitigate over-saturation and plastic-face issues. The new version shows consistent improvements over the previous release.</li>
402
+ <li><b>2025.05.13:</b> 'DreamO Video' Integration version Release</li>
403
+ </ul>
404
+ </div>
405
  '''
406
 
407
  _CITE_ = r"""
408
+ <div style="background: white; padding: 20px; border-radius: 12px; margin-top: 20px; box-shadow: 0 5px 15px rgba(0,0,0,0.05);">
409
+ <p style="margin: 0; font-size: 1.1rem;">If DreamO is helpful, please help to ⭐ the <a href='https://discord.gg/openfreeai' target='_blank' style="color: #9c27b0; font-weight: 600;">community</a>. Thanks!</p>
410
+ <hr style="border: none; height: 1px; background-color: #e0e0e0; margin: 15px 0;">
411
+ <h4 style="margin: 0 0 10px; color: #7b1fa2;">📧 Contact</h4>
412
+ <p style="margin: 0;">If you have any questions or feedback, feel free to open a discussion or contact <b>[email protected]</b></p>
413
+ </div>
414
  """
415
 
416
  def create_demo():
417
+ with gr.Blocks(css=_CUSTOM_CSS_) as demo:
418
+ gr.HTML(_HEADER_)
 
419
 
420
  with gr.Row():
421
+ with gr.Column(scale=6):
422
+ # Input panel - using a Group div with custom class instead of Box
423
+ with gr.Group(elem_id="input-panel", elem_classes="panel-box"):
424
+ gr.Markdown("### 📸 Reference Images")
425
+ with gr.Row():
426
+ with gr.Column():
427
+ ref_image1 = gr.Image(label="Reference Image 1", type="numpy", height=256, elem_id="ref-image-1")
428
+ ref_task1 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="Task for Reference Image 1", elem_id="ref-task-1")
429
+
430
+ with gr.Column():
431
+ ref_image2 = gr.Image(label="Reference Image 2", type="numpy", height=256, elem_id="ref-image-2")
432
+ ref_task2 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="Task for Reference Image 2", elem_id="ref-task-2")
433
+
434
+ gr.Markdown("### ✏️ Generation Parameters")
435
+ prompt = gr.Textbox(label="Prompt", value="a person playing guitar in the street", elem_id="prompt-input")
436
+
437
+ with gr.Row():
438
+ width = gr.Slider(768, 1024, 1024, step=16, label="Width", elem_id="width-slider")
439
+ height = gr.Slider(768, 1024, 1024, step=16, label="Height", elem_id="height-slider")
440
+
441
+ with gr.Row():
442
+ num_steps = gr.Slider(8, 30, 12, step=1, label="Number of Steps", elem_id="steps-slider")
443
+ guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Guidance Scale", elem_id="guidance-slider")
444
+
445
+ seed = gr.Textbox(label="Seed (-1 for random)", value="-1", elem_id="seed-input")
446
+
447
+ with gr.Accordion("Advanced Options", open=False):
448
+ ref_res = gr.Slider(512, 1024, 512, step=16, label="Resolution for Reference Image")
449
+ neg_prompt = gr.Textbox(label="Negative Prompt", value="")
450
+ neg_guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Negative Guidance")
451
+
452
+ with gr.Row():
453
+ true_cfg = gr.Slider(1, 5, 1, step=0.1, label="True CFG")
454
+ first_step_guidance = gr.Slider(0, 10, 0, step=0.1, label="First Step Guidance")
455
+
456
+ with gr.Row():
457
+ cfg_start_step = gr.Slider(0, 30, 0, step=1, label="CFG Start Step")
458
+ cfg_end_step = gr.Slider(0, 30, 0, step=1, label="CFG End Step")
459
+
460
+ generate_btn = gr.Button("✨ Generate Image", elem_id="generate-btn")
461
+ gr.HTML(_CITE_)
462
+
463
+ with gr.Column(scale=6):
464
+ # Output panel - using a Group div with custom class instead of Box
465
+ with gr.Group(elem_id="output-panel", elem_classes="panel-box"):
466
+ gr.Markdown("### 🖼️ Generated Result")
467
+ output_image = gr.Image(label="Generated Image", elem_id="output-image", format='png')
468
+ seed_output = gr.Textbox(label="Used Seed", elem_id="seed-output")
469
+
470
+ gr.Markdown("### 🔍 Preprocessing")
471
+ debug_image = gr.Gallery(
472
+ label="Preprocessing Results (including face crop and background removal)",
473
+ elem_id="debug-gallery",
474
+ )
475
+
476
+ # Examples panel - using a Group div with custom class instead of Box
477
+ with gr.Group(elem_id="examples-panel", elem_classes="panel-box"):
478
+ gr.Markdown("## 📚 Examples")
479
  example_inps = [
480
  [
481
+ 'example_inputs/choi.jpg',
 
 
 
 
 
 
 
 
482
  None,
483
  'ip',
484
  'ip',
485
+ 'a woman sitting on the cloud, playing guitar',
486
  1206523688721442817,
487
  ],
488
  [
489
  'example_inputs/toy1.png',
490
  None,
491
+ 'id',
492
  'ip',
493
+ 'a woman holding a sign saying "TOP", on the mountain',
 
494
  10441727852953907380,
495
  ],
496
  [
 
502
  116150031980664704,
503
  ],
504
  [
505
+ 'example_inputs/choi.jpg',
506
  None,
507
  'id',
508
  'ip',
509
+ 'portrait, wonder woman',
510
  5443415087540486371,
511
  ],
512
  [
 
549
  'two dogs in the jungle',
550
  6187006025405083344,
551
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
  ]
553
  gr.Examples(
554
  examples=example_inps,
555
  inputs=[ref_image1, ref_image2, ref_task1, ref_task2, prompt, seed],
556
+ label='Examples by category: IP task (rows 1-4), ID task (row 5), Style task (rows 6-7), Try-On task (rows 8-9), Multi IP (rows 10-12)',
557
  cache_examples='lazy',
558
  outputs=[output_image, debug_image, seed_output],
559
  fn=generate_image,
 
588
 
589
  if __name__ == '__main__':
590
  demo = create_demo()
591
+ demo.launch()