Spaces:
Running
on
Zero
Running
on
Zero
test
Browse files- __pycache__/dreamfuse_inference.cpython-310.pyc +0 -0
- app.py +114 -49
__pycache__/dreamfuse_inference.cpython-310.pyc
CHANGED
Binary files a/__pycache__/dreamfuse_inference.cpython-310.pyc and b/__pycache__/dreamfuse_inference.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -40,6 +40,10 @@ class DreamblendGUI:
|
|
40 |
self.examples = [
|
41 |
["./examples/9_02.png",
|
42 |
"./examples/9_01.png"],
|
|
|
|
|
|
|
|
|
43 |
]
|
44 |
self.examples = [[Image.open(x) for x in example] for example in self.examples]
|
45 |
self.css_style = self._get_css_style()
|
@@ -47,46 +51,86 @@ class DreamblendGUI:
|
|
47 |
|
48 |
def _get_css_style(self):
|
49 |
return """
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
body {
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
}
|
55 |
.gradio-container {
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
}
|
63 |
h1, h2 {
|
64 |
-
|
65 |
-
|
66 |
}
|
67 |
#canvas_preview {
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
.gr-button {
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
}
|
82 |
.gr-button:hover {
|
83 |
-
|
84 |
}
|
85 |
#small-examples {
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
}
|
91 |
"""
|
92 |
|
@@ -353,9 +397,9 @@ class DreamblendGUI:
|
|
353 |
</style>
|
354 |
</head>
|
355 |
<body>
|
356 |
-
<h2
|
357 |
<div id="scale-control">
|
358 |
-
<label for="scale-slider"
|
359 |
<input type="range" id="scale-slider" min="0.1" max="2" step="0.01" value="1">
|
360 |
</div>
|
361 |
<div id="canvas-container" data-bg-width="{bg_width}" data-bg-height="{bg_height}">
|
@@ -367,7 +411,7 @@ class DreamblendGUI:
|
|
367 |
data-original-height="{draggable_height}"
|
368 |
/>
|
369 |
</div>
|
370 |
-
<p id="coordinate"
|
371 |
</body>
|
372 |
</html>
|
373 |
"""
|
@@ -411,29 +455,50 @@ class DreamblendGUI:
|
|
411 |
"""创建 Gradio 界面"""
|
412 |
with gr.Blocks(css=self.css_style) as demo:
|
413 |
modified_fg_state = gr.State()
|
414 |
-
gr.Markdown("# DreamFuse
|
415 |
-
gr.Markdown(
|
416 |
-
gr.Markdown(
|
417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
with gr.Row():
|
419 |
-
with gr.Column(scale=1):
|
420 |
-
gr.Markdown("### FG&BG Image Upload")
|
421 |
-
|
422 |
-
|
423 |
-
|
|
|
|
|
|
|
424 |
|
425 |
with gr.Row():
|
426 |
-
gr.
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
gr.Markdown("### Preview Region")
|
433 |
-
html_out = gr.HTML(
|
|
|
|
|
|
|
|
|
434 |
|
435 |
with gr.Row():
|
436 |
-
with gr.Column(scale=1):
|
437 |
gr.Markdown("### Parameters")
|
438 |
seed_slider = gr.Slider(minimum=-1, maximum=100000, step=1, label="Seed", value=12345)
|
439 |
cfg_slider = gr.Slider(minimum=1, maximum=10, step=0.1, label="CFG", value=3.5)
|
@@ -446,9 +511,9 @@ class DreamblendGUI:
|
|
446 |
text_strength = gr.Slider(minimum=1, maximum=10, step=1, label="Text Strength", value=1, visible=False)
|
447 |
enable_gui = gr.Checkbox(label="启用GUI", value=True, visible=False)
|
448 |
enable_truecfg = gr.Checkbox(label="TrueCFG", value=False, visible=False)
|
449 |
-
with gr.Column(scale=1):
|
450 |
gr.Markdown("### Model Result")
|
451 |
-
model_generate_btn = gr.Button("Run Model")
|
452 |
transformation_text = gr.Textbox(label="Transformation Info", elem_id="transformation_info", visible=False)
|
453 |
model_output = gr.Image(label="Model Output", type="pil")
|
454 |
|
|
|
40 |
self.examples = [
|
41 |
["./examples/9_02.png",
|
42 |
"./examples/9_01.png"],
|
43 |
+
["./examples/010_1.webp",
|
44 |
+
"./examples/010_0.webp"],
|
45 |
+
["./examples/030_1.webp",
|
46 |
+
"./examples/030_0.webp"]
|
47 |
]
|
48 |
self.examples = [[Image.open(x) for x in example] for example in self.examples]
|
49 |
self.css_style = self._get_css_style()
|
|
|
51 |
|
52 |
def _get_css_style(self):
|
53 |
return """
|
54 |
+
input[type="file"] {
|
55 |
+
border: 1px solid #ccc !important;
|
56 |
+
background-color: #f9f9f9 !important;
|
57 |
+
padding: 8px !important;
|
58 |
+
border-radius: 6px !important;
|
59 |
+
}
|
60 |
body {
|
61 |
+
background-color: #ffffff;
|
62 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
63 |
+
color: #212121;
|
64 |
}
|
65 |
.gradio-container {
|
66 |
+
max-width: 1200px;
|
67 |
+
margin: auto;
|
68 |
+
background: #ffffff;
|
69 |
+
border-radius: 12px;
|
70 |
+
padding: 24px;
|
71 |
+
box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.05);
|
72 |
}
|
73 |
h1, h2 {
|
74 |
+
text-align: center;
|
75 |
+
color: #222;
|
76 |
}
|
77 |
#canvas_preview {
|
78 |
+
min-height: 420px; /* 或你需要的高度 */
|
79 |
+
border: 2px dashed #ccc;
|
80 |
+
background-color: #fafafa;
|
81 |
+
border-radius: 8px;
|
82 |
+
padding: 10px;
|
83 |
+
display: flex;
|
84 |
+
justify-content: center;
|
85 |
+
align-items: center;
|
86 |
+
color: #999;
|
87 |
+
font-size: 16px;
|
88 |
}
|
89 |
.gr-button {
|
90 |
+
background-color: #2196f3;
|
91 |
+
border: 1px solid #1976d2;
|
92 |
+
color: #ffffff;
|
93 |
+
padding: 10px 20px;
|
94 |
+
border-radius: 6px;
|
95 |
+
font-size: 15px;
|
96 |
+
cursor: pointer;
|
97 |
+
transition: background-color 0.2s ease;
|
98 |
}
|
99 |
.gr-button:hover {
|
100 |
+
background-color: #1976d2;
|
101 |
}
|
102 |
#small-examples {
|
103 |
+
width: 200px;
|
104 |
+
margin: 10px 0;
|
105 |
+
border: 1px solid #ddd;
|
106 |
+
border-radius: 8px;
|
107 |
+
overflow: hidden;
|
108 |
+
background: #fff;
|
109 |
+
box-shadow: 0 1px 4px rgba(0,0,0,0.05);
|
110 |
+
}
|
111 |
+
.markdown-text {
|
112 |
+
color: #333;
|
113 |
+
font-size: 15px;
|
114 |
+
line-height: 1.6;
|
115 |
+
}
|
116 |
+
#canvas-preview-container {
|
117 |
+
background: #fafafa;
|
118 |
+
border: 1px solid #ddd;
|
119 |
+
border-radius: 8px;
|
120 |
+
padding: 10px;
|
121 |
+
margin-top: 10px;
|
122 |
+
}
|
123 |
+
[id^="section-"] {
|
124 |
+
background-color: #ffffff;
|
125 |
+
border: 1px solid #dddddd;
|
126 |
+
border-radius: 10px;
|
127 |
+
padding: 16px;
|
128 |
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
|
129 |
+
margin-bottom: 16px;
|
130 |
+
}
|
131 |
+
.svelte-1ipelgc {
|
132 |
+
flex-wrap: nowrap !important;
|
133 |
+
gap: 24px !important; /* 每块之间增加空隙 */
|
134 |
}
|
135 |
"""
|
136 |
|
|
|
397 |
</style>
|
398 |
</head>
|
399 |
<body>
|
400 |
+
<h2> 3️⃣ Drag and Resize</h2>
|
401 |
<div id="scale-control">
|
402 |
+
<label for="scale-slider">Resize FG:</label>
|
403 |
<input type="range" id="scale-slider" min="0.1" max="2" step="0.01" value="1">
|
404 |
</div>
|
405 |
<div id="canvas-container" data-bg-width="{bg_width}" data-bg-height="{bg_height}">
|
|
|
411 |
data-original-height="{draggable_height}"
|
412 |
/>
|
413 |
</div>
|
414 |
+
<p id="coordinate">location: (x=?, y=?)</p>
|
415 |
</body>
|
416 |
</html>
|
417 |
"""
|
|
|
455 |
"""创建 Gradio 界面"""
|
456 |
with gr.Blocks(css=self.css_style) as demo:
|
457 |
modified_fg_state = gr.State()
|
458 |
+
gr.Markdown("# DreamFuse")
|
459 |
+
gr.Markdown('## 📌 4 Easy Steps to Create Your Fusion Image:')
|
460 |
+
gr.Markdown(
|
461 |
+
"""
|
462 |
+
1. Upload the foreground and background images you want to fuse.
|
463 |
+
2. Click 'Generate Canvas' to preview the result.
|
464 |
+
3. Drag and resize the foreground object to position it as you like.
|
465 |
+
4. Click 'Run Model' to create the final fused image.
|
466 |
+
""",
|
467 |
+
elem_classes=["markdown-text"]
|
468 |
+
)
|
469 |
with gr.Row():
|
470 |
+
with gr.Column(scale=1, elem_id="section-upload"):
|
471 |
+
gr.Markdown("### 1️⃣ FG&BG Image Upload")
|
472 |
+
with gr.Row():
|
473 |
+
with gr.Column(scale=1):
|
474 |
+
background_img_in = gr.Image(label="Background Image", type="pil", height=240, width=200)
|
475 |
+
with gr.Column(scale=1):
|
476 |
+
draggable_img_in = gr.Image(label="Foreground Image", type="pil", image_mode="RGBA", height=240, width=200)
|
477 |
+
generate_btn = gr.Button("2️⃣ Generate Canvas")
|
478 |
|
479 |
with gr.Row():
|
480 |
+
with gr.Column(scale=1):
|
481 |
+
gr.Examples(
|
482 |
+
examples=[self.examples[1]],
|
483 |
+
inputs=[background_img_in, draggable_img_in],
|
484 |
+
# elem_id="small-examples"
|
485 |
+
)
|
486 |
+
with gr.Column(scale=1):
|
487 |
+
gr.Examples(
|
488 |
+
examples=[self.examples[2]],
|
489 |
+
inputs=[background_img_in, draggable_img_in],
|
490 |
+
# elem_id="small-examples"
|
491 |
+
)
|
492 |
+
with gr.Column(scale=1, elem_id="section-preview"):
|
493 |
gr.Markdown("### Preview Region")
|
494 |
+
html_out = gr.HTML(
|
495 |
+
value="<p style='text-align:center; color:#aaa;'>Waiting for generating canvas...</p>",
|
496 |
+
label="drag and resize",
|
497 |
+
elem_id="canvas_preview"
|
498 |
+
)
|
499 |
|
500 |
with gr.Row():
|
501 |
+
with gr.Column(scale=1, elem_id="section-parameters"):
|
502 |
gr.Markdown("### Parameters")
|
503 |
seed_slider = gr.Slider(minimum=-1, maximum=100000, step=1, label="Seed", value=12345)
|
504 |
cfg_slider = gr.Slider(minimum=1, maximum=10, step=0.1, label="CFG", value=3.5)
|
|
|
511 |
text_strength = gr.Slider(minimum=1, maximum=10, step=1, label="Text Strength", value=1, visible=False)
|
512 |
enable_gui = gr.Checkbox(label="启用GUI", value=True, visible=False)
|
513 |
enable_truecfg = gr.Checkbox(label="TrueCFG", value=False, visible=False)
|
514 |
+
with gr.Column(scale=1, elem_id="section-results"):
|
515 |
gr.Markdown("### Model Result")
|
516 |
+
model_generate_btn = gr.Button("4️⃣ Run Model")
|
517 |
transformation_text = gr.Textbox(label="Transformation Info", elem_id="transformation_info", visible=False)
|
518 |
model_output = gr.Image(label="Model Output", type="pil")
|
519 |
|