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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
import shutil
|
5 |
+
import cv2
|
6 |
+
import gradio as gr
|
7 |
+
import numpy as np
|
8 |
+
import torch
|
9 |
+
from facexlib.utils.face_restoration_helper import FaceRestoreHelper
|
10 |
+
import huggingface_hub
|
11 |
+
from huggingface_hub import hf_hub_download
|
12 |
+
from PIL import Image
|
13 |
+
from torchvision.transforms.functional import normalize
|
14 |
+
|
15 |
+
from dreamo.dreamo_pipeline import DreamOPipeline
|
16 |
+
from dreamo.utils import img2tensor, resize_numpy_image_area, tensor2img, resize_numpy_image_long
|
17 |
+
from tools import BEN2
|
18 |
+
|
19 |
+
parser = argparse.ArgumentParser()
|
20 |
+
parser.add_argument('--port', type=int, default=8080)
|
21 |
+
parser.add_argument('--no_turbo', action='store_true')
|
22 |
+
args = parser.parse_args()
|
23 |
+
|
24 |
+
huggingface_hub.login(os.getenv('HF_TOKEN'))
|
25 |
+
|
26 |
+
try:
|
27 |
+
shutil.rmtree('gradio_cached_examples')
|
28 |
+
except FileNotFoundError:
|
29 |
+
print("cache folder not exist")
|
30 |
+
|
31 |
+
class Generator:
|
32 |
+
def __init__(self):
|
33 |
+
device = torch.device('cuda')
|
34 |
+
# preprocessing models
|
35 |
+
# background remove model: BEN2
|
36 |
+
self.bg_rm_model = BEN2.BEN_Base().to(device).eval()
|
37 |
+
hf_hub_download(repo_id='PramaLLC/BEN2', filename='BEN2_Base.pth', local_dir='models')
|
38 |
+
self.bg_rm_model.loadcheckpoints('models/BEN2_Base.pth')
|
39 |
+
# face crop and align tool: facexlib
|
40 |
+
self.face_helper = FaceRestoreHelper(
|
41 |
+
upscale_factor=1,
|
42 |
+
face_size=512,
|
43 |
+
crop_ratio=(1, 1),
|
44 |
+
det_model='retinaface_resnet50',
|
45 |
+
save_ext='png',
|
46 |
+
device=device,
|
47 |
+
)
|
48 |
+
|
49 |
+
# load dreamo
|
50 |
+
model_root = 'black-forest-labs/FLUX.1-dev'
|
51 |
+
dreamo_pipeline = DreamOPipeline.from_pretrained(model_root, torch_dtype=torch.bfloat16)
|
52 |
+
dreamo_pipeline.load_dreamo_model(device, use_turbo=not args.no_turbo)
|
53 |
+
self.dreamo_pipeline = dreamo_pipeline.to(device)
|
54 |
+
|
55 |
+
@torch.no_grad()
|
56 |
+
def get_align_face(self, img):
|
57 |
+
# the face preprocessing code is same as PuLID
|
58 |
+
self.face_helper.clean_all()
|
59 |
+
image_bgr = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
60 |
+
self.face_helper.read_image(image_bgr)
|
61 |
+
self.face_helper.get_face_landmarks_5(only_center_face=True)
|
62 |
+
self.face_helper.align_warp_face()
|
63 |
+
if len(self.face_helper.cropped_faces) == 0:
|
64 |
+
return None
|
65 |
+
align_face = self.face_helper.cropped_faces[0]
|
66 |
+
|
67 |
+
input = img2tensor(align_face, bgr2rgb=True).unsqueeze(0) / 255.0
|
68 |
+
input = input.to(torch.device("cuda"))
|
69 |
+
parsing_out = self.face_helper.face_parse(normalize(input, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]))[0]
|
70 |
+
parsing_out = parsing_out.argmax(dim=1, keepdim=True)
|
71 |
+
bg_label = [0, 16, 18, 7, 8, 9, 14, 15]
|
72 |
+
bg = sum(parsing_out == i for i in bg_label).bool()
|
73 |
+
white_image = torch.ones_like(input)
|
74 |
+
# only keep the face features
|
75 |
+
face_features_image = torch.where(bg, white_image, input)
|
76 |
+
face_features_image = tensor2img(face_features_image, rgb2bgr=False)
|
77 |
+
|
78 |
+
return face_features_image
|
79 |
+
|
80 |
+
|
81 |
+
generator = Generator()
|
82 |
+
|
83 |
+
|
84 |
+
@spaces.GPU
|
85 |
+
@torch.inference_mode()
|
86 |
+
def generate_image(
|
87 |
+
ref_image1,
|
88 |
+
ref_image2,
|
89 |
+
ref_task1,
|
90 |
+
ref_task2,
|
91 |
+
prompt,
|
92 |
+
seed,
|
93 |
+
width=1024,
|
94 |
+
height=1024,
|
95 |
+
ref_res=512,
|
96 |
+
num_steps=12,
|
97 |
+
guidance=3.5,
|
98 |
+
true_cfg=1,
|
99 |
+
cfg_start_step=0,
|
100 |
+
cfg_end_step=0,
|
101 |
+
neg_prompt='',
|
102 |
+
neg_guidance=3.5,
|
103 |
+
first_step_guidance=0,
|
104 |
+
):
|
105 |
+
print(prompt)
|
106 |
+
ref_conds = []
|
107 |
+
debug_images = []
|
108 |
+
|
109 |
+
ref_images = [ref_image1, ref_image2]
|
110 |
+
ref_tasks = [ref_task1, ref_task2]
|
111 |
+
|
112 |
+
for idx, (ref_image, ref_task) in enumerate(zip(ref_images, ref_tasks)):
|
113 |
+
if ref_image is not None:
|
114 |
+
if ref_task == "id":
|
115 |
+
ref_image = resize_numpy_image_long(ref_image, 1024)
|
116 |
+
ref_image = generator.get_align_face(ref_image)
|
117 |
+
elif ref_task != "style":
|
118 |
+
ref_image = generator.bg_rm_model.inference(Image.fromarray(ref_image))
|
119 |
+
if ref_task != "id":
|
120 |
+
ref_image = resize_numpy_image_area(np.array(ref_image), ref_res * ref_res)
|
121 |
+
debug_images.append(ref_image)
|
122 |
+
ref_image = img2tensor(ref_image, bgr2rgb=False).unsqueeze(0) / 255.0
|
123 |
+
ref_image = 2 * ref_image - 1.0
|
124 |
+
ref_conds.append(
|
125 |
+
{
|
126 |
+
'img': ref_image,
|
127 |
+
'task': ref_task,
|
128 |
+
'idx': idx + 1,
|
129 |
+
}
|
130 |
+
)
|
131 |
+
|
132 |
+
seed = int(seed)
|
133 |
+
if seed == -1:
|
134 |
+
seed = torch.Generator(device="cpu").seed()
|
135 |
+
|
136 |
+
image = generator.dreamo_pipeline(
|
137 |
+
prompt=prompt,
|
138 |
+
width=width,
|
139 |
+
height=height,
|
140 |
+
num_inference_steps=num_steps,
|
141 |
+
guidance_scale=guidance,
|
142 |
+
ref_conds=ref_conds,
|
143 |
+
generator=torch.Generator(device="cpu").manual_seed(seed),
|
144 |
+
true_cfg_scale=true_cfg,
|
145 |
+
true_cfg_start_step=cfg_start_step,
|
146 |
+
true_cfg_end_step=cfg_end_step,
|
147 |
+
negative_prompt=neg_prompt,
|
148 |
+
neg_guidance_scale=neg_guidance,
|
149 |
+
first_step_guidance_scale=first_step_guidance if first_step_guidance > 0 else guidance,
|
150 |
+
).images[0]
|
151 |
+
|
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 */
|
189 |
+
.gr-box, .gr-form, .gr-panel {
|
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 |
+
}
|
196 |
+
|
197 |
+
/* Button styling */
|
198 |
+
button.gr-button {
|
199 |
+
background: linear-gradient(135deg, var(--primary-color), #e1bee7) !important;
|
200 |
+
border-radius: var(--border-radius) !important;
|
201 |
+
color: #4a148c !important;
|
202 |
+
font-weight: 600 !important;
|
203 |
+
border: none !important;
|
204 |
+
padding: 10px 20px !important;
|
205 |
+
transition: all 0.3s ease !important;
|
206 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
|
207 |
+
}
|
208 |
+
|
209 |
+
button.gr-button:hover {
|
210 |
+
transform: translateY(-2px) !important;
|
211 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15) !important;
|
212 |
+
background: linear-gradient(135deg, #e1bee7, var(--primary-color)) !important;
|
213 |
+
}
|
214 |
+
|
215 |
+
/* Input fields styling */
|
216 |
+
input, select, textarea, .gr-input {
|
217 |
+
border-radius: 8px !important;
|
218 |
+
border: 2px solid #e0e0e0 !important;
|
219 |
+
padding: 10px 15px !important;
|
220 |
+
transition: all 0.3s ease !important;
|
221 |
+
background-color: #fafafa !important;
|
222 |
+
}
|
223 |
+
|
224 |
+
input:focus, select:focus, textarea:focus, .gr-input:focus {
|
225 |
+
border-color: var(--primary-color) !important;
|
226 |
+
box-shadow: 0 0 0 3px rgba(248, 195, 205, 0.3) !important;
|
227 |
+
}
|
228 |
+
|
229 |
+
/* Slider styling */
|
230 |
+
.gr-slider {
|
231 |
+
--slider-color: var(--primary-color) !important;
|
232 |
+
}
|
233 |
+
|
234 |
+
.gr-slider-handle {
|
235 |
+
background-color: white !important;
|
236 |
+
border: 2px solid var(--primary-color) !important;
|
237 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
|
238 |
+
}
|
239 |
+
|
240 |
+
/* Dropdown styling */
|
241 |
+
.gr-dropdown {
|
242 |
+
background-color: white !important;
|
243 |
+
border: 2px solid #e0e0e0 !important;
|
244 |
+
border-radius: 8px !important;
|
245 |
+
}
|
246 |
+
|
247 |
+
.gr-dropdown option {
|
248 |
+
padding: 10px !important;
|
249 |
+
}
|
250 |
+
|
251 |
+
/* Image upload area */
|
252 |
+
.gr-image-input {
|
253 |
+
border: 2px dashed #b39ddb !important;
|
254 |
+
border-radius: var(--border-radius) !important;
|
255 |
+
background-color: #f3e5f5 !important;
|
256 |
+
padding: 20px !important;
|
257 |
+
display: flex !important;
|
258 |
+
flex-direction: column !important;
|
259 |
+
align-items: center !important;
|
260 |
+
justify-content: center !important;
|
261 |
+
transition: all 0.3s ease !important;
|
262 |
+
}
|
263 |
+
|
264 |
+
.gr-image-input:hover {
|
265 |
+
background-color: #ede7f6 !important;
|
266 |
+
border-color: #9575cd !important;
|
267 |
+
}
|
268 |
+
|
269 |
+
/* Add a nice pattern to the background */
|
270 |
+
body::before {
|
271 |
+
content: "" !important;
|
272 |
+
position: fixed !important;
|
273 |
+
top: 0 !important;
|
274 |
+
left: 0 !important;
|
275 |
+
width: 100% !important;
|
276 |
+
height: 100% !important;
|
277 |
+
background:
|
278 |
+
radial-gradient(circle at 10% 20%, rgba(248, 195, 205, 0.1) 0%, rgba(245, 245, 247, 0) 20%),
|
279 |
+
radial-gradient(circle at 80% 70%, rgba(179, 229, 252, 0.1) 0%, rgba(245, 245, 247, 0) 20%) !important;
|
280 |
+
pointer-events: none !important;
|
281 |
+
z-index: -1 !important;
|
282 |
+
}
|
283 |
+
|
284 |
+
/* Gallery styling */
|
285 |
+
.gr-gallery {
|
286 |
+
grid-gap: 15px !important;
|
287 |
+
}
|
288 |
+
|
289 |
+
.gr-gallery-item {
|
290 |
+
border-radius: var(--border-radius) !important;
|
291 |
+
overflow: hidden !important;
|
292 |
+
box-shadow: 0 4px 8px var(--shadow-color) !important;
|
293 |
+
transition: transform 0.3s ease !important;
|
294 |
+
}
|
295 |
+
|
296 |
+
.gr-gallery-item:hover {
|
297 |
+
transform: scale(1.02) !important;
|
298 |
+
}
|
299 |
+
|
300 |
+
/* Label styling */
|
301 |
+
label {
|
302 |
+
font-weight: 600 !important;
|
303 |
+
color: #673ab7 !important;
|
304 |
+
margin-bottom: 5px !important;
|
305 |
+
}
|
306 |
+
|
307 |
+
/* Improve spacing */
|
308 |
+
.gr-padded {
|
309 |
+
padding: 20px !important;
|
310 |
+
}
|
311 |
+
|
312 |
+
.gr-compact {
|
313 |
+
gap: 15px !important;
|
314 |
+
}
|
315 |
+
|
316 |
+
.gr-form > *, .gr-box > * {
|
317 |
+
margin-bottom: 16px !important;
|
318 |
+
}
|
319 |
+
|
320 |
+
/* Update Examples section */
|
321 |
+
.gr-examples {
|
322 |
+
background-color: #f3e5f5 !important;
|
323 |
+
border-radius: var(--border-radius) !important;
|
324 |
+
padding: 15px !important;
|
325 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05) !important;
|
326 |
+
}
|
327 |
+
|
328 |
+
.gr-examples h2 {
|
329 |
+
color: #7b1fa2 !important;
|
330 |
+
font-size: 1.5rem !important;
|
331 |
+
margin-bottom: 15px !important;
|
332 |
+
}
|
333 |
+
|
334 |
+
/* Dropdown menu adjustments */
|
335 |
+
.gr-dropdowns {
|
336 |
+
display: flex !important;
|
337 |
+
gap: 10px !important;
|
338 |
+
}
|
339 |
+
|
340 |
+
/* Status messages */
|
341 |
+
.gr-status {
|
342 |
+
border-radius: 8px !important;
|
343 |
+
padding: 10px 15px !important;
|
344 |
+
}
|
345 |
+
|
346 |
+
.gr-info {
|
347 |
+
background-color: var(--secondary-color) !important;
|
348 |
+
}
|
349 |
+
|
350 |
+
.gr-warning {
|
351 |
+
background-color: var(--warning-color) !important;
|
352 |
+
}
|
353 |
+
|
354 |
+
.gr-error {
|
355 |
+
background-color: #ffcdd2 !important;
|
356 |
+
}
|
357 |
+
"""
|
358 |
+
|
359 |
+
_HEADER_ = '''
|
360 |
+
<div style="text-align: center; max-width: 850px; margin: 0 auto; padding: 25px 0;">
|
361 |
+
<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;">
|
362 |
+
<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>
|
363 |
+
<p style="font-size: 1.2rem; margin: 10px 0 0;">Create customized images with advanced AI</p>
|
364 |
+
</div>
|
365 |
+
<div style="background: white; padding: 15px; border-radius: 12px; box-shadow: 0 5px 15px rgba(0,0,0,0.05);">
|
366 |
+
<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> |
|
367 |
+
Codes: <a href='https://github.com/bytedance/DreamO' target='_blank' style="color: #9c27b0; font-weight: 600;">GitHub</a></p>
|
368 |
+
</div>
|
369 |
+
</div>
|
370 |
+
|
371 |
+
<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);">
|
372 |
+
<h3 style="margin-top: 0; color: #ff6f00;">🚩 Update Notes:</h3>
|
373 |
+
<ul style="margin-bottom: 0; padding-left: 20px;">
|
374 |
+
<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>
|
375 |
+
<li><b>2025.05.13:</b> 'DreamO Video' Integration version Release</li>
|
376 |
+
</ul>
|
377 |
+
</div>
|
378 |
+
'''
|
379 |
+
|
380 |
+
_CITE_ = r"""
|
381 |
+
<div style="background: white; padding: 20px; border-radius: 12px; margin-top: 20px; box-shadow: 0 5px 15px rgba(0,0,0,0.05);">
|
382 |
+
<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>
|
383 |
+
<hr style="border: none; height: 1px; background-color: #e0e0e0; margin: 15px 0;">
|
384 |
+
<h4 style="margin: 0 0 10px; color: #7b1fa2;">📧 Contact</h4>
|
385 |
+
<p style="margin: 0;">If you have any questions or feedback, feel free to open a discussion or contact <b>[email protected]</b></p>
|
386 |
+
</div>
|
387 |
+
"""
|
388 |
+
|
389 |
+
def create_demo():
|
390 |
+
with gr.Blocks(css=_CUSTOM_CSS_) as demo:
|
391 |
+
gr.HTML(_HEADER_)
|
392 |
+
|
393 |
+
with gr.Row():
|
394 |
+
with gr.Column(scale=6):
|
395 |
+
with gr.Box(elem_id="input-panel"):
|
396 |
+
gr.Markdown("### 📸 Reference Images")
|
397 |
+
with gr.Row():
|
398 |
+
with gr.Column():
|
399 |
+
ref_image1 = gr.Image(label="Reference Image 1", type="numpy", height=256, elem_id="ref-image-1")
|
400 |
+
ref_task1 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="Task for Reference Image 1", elem_id="ref-task-1")
|
401 |
+
|
402 |
+
with gr.Column():
|
403 |
+
ref_image2 = gr.Image(label="Reference Image 2", type="numpy", height=256, elem_id="ref-image-2")
|
404 |
+
ref_task2 = gr.Dropdown(choices=["ip", "id", "style"], value="ip", label="Task for Reference Image 2", elem_id="ref-task-2")
|
405 |
+
|
406 |
+
gr.Markdown("### ✏️ Generation Parameters")
|
407 |
+
prompt = gr.Textbox(label="Prompt", value="a person playing guitar in the street", elem_id="prompt-input")
|
408 |
+
|
409 |
+
with gr.Row():
|
410 |
+
width = gr.Slider(768, 1024, 1024, step=16, label="Width", elem_id="width-slider")
|
411 |
+
height = gr.Slider(768, 1024, 1024, step=16, label="Height", elem_id="height-slider")
|
412 |
+
|
413 |
+
with gr.Row():
|
414 |
+
num_steps = gr.Slider(8, 30, 12, step=1, label="Number of Steps", elem_id="steps-slider")
|
415 |
+
guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Guidance Scale", elem_id="guidance-slider")
|
416 |
+
|
417 |
+
seed = gr.Textbox(label="Seed (-1 for random)", value="-1", elem_id="seed-input")
|
418 |
+
|
419 |
+
with gr.Accordion("Advanced Options", open=False):
|
420 |
+
ref_res = gr.Slider(512, 1024, 512, step=16, label="Resolution for Reference Image")
|
421 |
+
neg_prompt = gr.Textbox(label="Negative Prompt", value="")
|
422 |
+
neg_guidance = gr.Slider(1.0, 10.0, 3.5, step=0.1, label="Negative Guidance")
|
423 |
+
|
424 |
+
with gr.Row():
|
425 |
+
true_cfg = gr.Slider(1, 5, 1, step=0.1, label="True CFG")
|
426 |
+
first_step_guidance = gr.Slider(0, 10, 0, step=0.1, label="First Step Guidance")
|
427 |
+
|
428 |
+
with gr.Row():
|
429 |
+
cfg_start_step = gr.Slider(0, 30, 0, step=1, label="CFG Start Step")
|
430 |
+
cfg_end_step = gr.Slider(0, 30, 0, step=1, label="CFG End Step")
|
431 |
+
|
432 |
+
generate_btn = gr.Button("✨ Generate Image", elem_id="generate-btn")
|
433 |
+
gr.HTML(_CITE_)
|
434 |
+
|
435 |
+
with gr.Column(scale=6):
|
436 |
+
with gr.Box(elem_id="output-panel"):
|
437 |
+
gr.Markdown("### 🖼️ Generated Result")
|
438 |
+
output_image = gr.Image(label="Generated Image", elem_id="output-image", format='png')
|
439 |
+
seed_output = gr.Textbox(label="Used Seed", elem_id="seed-output")
|
440 |
+
|
441 |
+
gr.Markdown("### 🔍 Preprocessing")
|
442 |
+
debug_image = gr.Gallery(
|
443 |
+
label="Preprocessing Results (including face crop and background removal)",
|
444 |
+
elem_id="debug-gallery",
|
445 |
+
)
|
446 |
+
|
447 |
+
with gr.Box(elem_id="examples-panel"):
|
448 |
+
gr.Markdown("## 📚 Examples")
|
449 |
+
example_inps = [
|
450 |
+
[
|
451 |
+
'example_inputs/woman1.png',
|
452 |
+
None,
|
453 |
+
'ip',
|
454 |
+
'ip',
|
455 |
+
'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
|
456 |
+
9180879731249039735,
|
457 |
+
],
|
458 |
+
[
|
459 |
+
'example_inputs/man1.png',
|
460 |
+
None,
|
461 |
+
'ip',
|
462 |
+
'ip',
|
463 |
+
'a man sitting on the cloud, playing guitar',
|
464 |
+
1206523688721442817,
|
465 |
+
],
|
466 |
+
[
|
467 |
+
'example_inputs/toy1.png',
|
468 |
+
None,
|
469 |
+
'ip',
|
470 |
+
'ip',
|
471 |
+
'a purple toy holding a sign saying "DreamO", on the mountain',
|
472 |
+
10441727852953907380,
|
473 |
+
],
|
474 |
+
[
|
475 |
+
'example_inputs/perfume.png',
|
476 |
+
None,
|
477 |
+
'ip',
|
478 |
+
'ip',
|
479 |
+
'a perfume under spotlight',
|
480 |
+
116150031980664704,
|
481 |
+
],
|
482 |
+
[
|
483 |
+
'example_inputs/hinton.jpeg',
|
484 |
+
None,
|
485 |
+
'id',
|
486 |
+
'ip',
|
487 |
+
'portrait, Chibi',
|
488 |
+
5443415087540486371,
|
489 |
+
],
|
490 |
+
[
|
491 |
+
'example_inputs/mickey.png',
|
492 |
+
None,
|
493 |
+
'style',
|
494 |
+
'ip',
|
495 |
+
'generate a same style image. A rooster wearing overalls.',
|
496 |
+
6245580464677124951,
|
497 |
+
],
|
498 |
+
[
|
499 |
+
'example_inputs/mountain.png',
|
500 |
+
None,
|
501 |
+
'style',
|
502 |
+
'ip',
|
503 |
+
'generate a same style image. A pavilion by the river, and the distant mountains are endless',
|
504 |
+
5248066378927500767,
|
505 |
+
],
|
506 |
+
[
|
507 |
+
'example_inputs/shirt.png',
|
508 |
+
'example_inputs/skirt.jpeg',
|
509 |
+
'ip',
|
510 |
+
'ip',
|
511 |
+
'A girl is wearing a short-sleeved shirt and a short skirt on the beach.',
|
512 |
+
9514069256241143615,
|
513 |
+
],
|
514 |
+
[
|
515 |
+
'example_inputs/woman2.png',
|
516 |
+
'example_inputs/dress.png',
|
517 |
+
'id',
|
518 |
+
'ip',
|
519 |
+
'the woman wearing a dress, In the banquet hall',
|
520 |
+
7698454872441022867,
|
521 |
+
],
|
522 |
+
[
|
523 |
+
'example_inputs/dog1.png',
|
524 |
+
'example_inputs/dog2.png',
|
525 |
+
'ip',
|
526 |
+
'ip',
|
527 |
+
'two dogs in the jungle',
|
528 |
+
6187006025405083344,
|
529 |
+
],
|
530 |
+
[
|
531 |
+
'example_inputs/woman3.png',
|
532 |
+
'example_inputs/cat.png',
|
533 |
+
'ip',
|
534 |
+
'ip',
|
535 |
+
'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
|
536 |
+
11980469406460273604,
|
537 |
+
],
|
538 |
+
[
|
539 |
+
'example_inputs/man2.jpeg',
|
540 |
+
'example_inputs/woman4.jpeg',
|
541 |
+
'ip',
|
542 |
+
'ip',
|
543 |
+
'a man is dancing with a woman in the room',
|
544 |
+
8303780338601106219,
|
545 |
+
],
|
546 |
+
]
|
547 |
+
gr.Examples(
|
548 |
+
examples=example_inps,
|
549 |
+
inputs=[ref_image1, ref_image2, ref_task1, ref_task2, prompt, seed],
|
550 |
+
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)',
|
551 |
+
cache_examples='lazy',
|
552 |
+
outputs=[output_image, debug_image, seed_output],
|
553 |
+
fn=generate_image,
|
554 |
+
)
|
555 |
+
|
556 |
+
generate_btn.click(
|
557 |
+
fn=generate_image,
|
558 |
+
inputs=[
|
559 |
+
ref_image1,
|
560 |
+
ref_image2,
|
561 |
+
ref_task1,
|
562 |
+
ref_task2,
|
563 |
+
prompt,
|
564 |
+
seed,
|
565 |
+
width,
|
566 |
+
height,
|
567 |
+
ref_res,
|
568 |
+
num_steps,
|
569 |
+
guidance,
|
570 |
+
true_cfg,
|
571 |
+
cfg_start_step,
|
572 |
+
cfg_end_step,
|
573 |
+
neg_prompt,
|
574 |
+
neg_guidance,
|
575 |
+
first_step_guidance,
|
576 |
+
],
|
577 |
+
outputs=[output_image, debug_image, seed_output],
|
578 |
+
)
|
579 |
+
|
580 |
+
return demo
|
581 |
+
|
582 |
+
|
583 |
+
if __name__ == '__main__':
|
584 |
+
demo = create_demo()
|
585 |
+
demo.launch()
|