1
commited on
Commit
·
25e816c
1
Parent(s):
631aa6b
Update app.py
Browse files
app.py
CHANGED
@@ -57,51 +57,152 @@ def create_demo(
|
|
57 |
pipeline = UNOPipeline(model_type, device, offload, only_lora=True, lora_rank=512)
|
58 |
pipeline.gradio_generate = spaces.GPU(duratioin=120)(pipeline.gradio_generate)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
badges_text = r"""
|
62 |
-
<div
|
63 |
-
<a href="https://github.com/bytedance/UNO"><img alt="
|
64 |
-
<a href="https://bytedance.github.io/UNO/"><img alt="
|
65 |
-
<a href="https://arxiv.org/abs/2504.02160"><img alt="
|
66 |
-
<a href="https://huggingface.co/bytedance-research/UNO"><img src="https://img.shields.io/static/v1?label=%F0%9F%A4%97%20Hugging%20Face&message=Model&color=orange"></a>
|
67 |
-
<a href="https://huggingface.co/spaces/bytedance-research/UNO-FLUX"><img src="https://img.shields.io/static/v1?label=%F0%9F%A4%97%20Hugging%20Face&message=demo&color=orange"></a>
|
68 |
</div>
|
69 |
""".strip()
|
70 |
|
71 |
-
with gr.Blocks() as demo:
|
72 |
-
gr.Markdown(
|
73 |
gr.Markdown(badges_text)
|
|
|
74 |
with gr.Row():
|
75 |
-
with gr.Column():
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
gr.
|
89 |
-
gr.
|
90 |
-
"The size closer to 512 is more stable,"
|
91 |
-
" and the higher size gives a better visual effect but is less stable"
|
92 |
-
)
|
93 |
-
|
94 |
-
with gr.Accordion("Advanced Options", open=False):
|
95 |
-
with gr.Row():
|
96 |
-
num_steps = gr.Slider(1, 50, 25, step=1, label="Number of steps")
|
97 |
-
guidance = gr.Slider(1.0, 5.0, 4.0, step=0.1, label="Guidance", interactive=True)
|
98 |
-
seed = gr.Number(-1, label="Seed (-1 for random)")
|
99 |
-
|
100 |
-
generate_btn = gr.Button("Generate")
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
|
107 |
inputs = [
|
@@ -117,14 +218,16 @@ def create_demo(
|
|
117 |
example_text = gr.Text("", visible=False, label="Case For:")
|
118 |
examples = get_examples("./assets/examples")
|
119 |
|
120 |
-
gr.
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
128 |
|
129 |
return demo
|
130 |
|
|
|
57 |
pipeline = UNOPipeline(model_type, device, offload, only_lora=True, lora_rank=512)
|
58 |
pipeline.gradio_generate = spaces.GPU(duratioin=120)(pipeline.gradio_generate)
|
59 |
|
60 |
+
# 自定义CSS样式
|
61 |
+
css = """
|
62 |
+
.gradio-container {
|
63 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
64 |
+
}
|
65 |
+
|
66 |
+
.main-header {
|
67 |
+
text-align: center;
|
68 |
+
margin-bottom: 2rem;
|
69 |
+
background: linear-gradient(to right, #4776E6, #8E54E9);
|
70 |
+
-webkit-background-clip: text;
|
71 |
+
-webkit-text-fill-color: transparent;
|
72 |
+
font-weight: 700;
|
73 |
+
padding: 1rem 0;
|
74 |
+
}
|
75 |
+
|
76 |
+
.container {
|
77 |
+
border-radius: 12px;
|
78 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
79 |
+
padding: 20px;
|
80 |
+
background: white;
|
81 |
+
margin-bottom: 1.5rem;
|
82 |
+
}
|
83 |
+
|
84 |
+
.input-container {
|
85 |
+
background: rgba(245, 247, 250, 0.7);
|
86 |
+
border-radius: 10px;
|
87 |
+
padding: 1rem;
|
88 |
+
margin-bottom: 1rem;
|
89 |
+
}
|
90 |
+
|
91 |
+
.image-grid {
|
92 |
+
display: grid;
|
93 |
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
94 |
+
gap: 10px;
|
95 |
+
}
|
96 |
+
|
97 |
+
.generate-btn {
|
98 |
+
background: linear-gradient(90deg, #4776E6, #8E54E9);
|
99 |
+
border: none;
|
100 |
+
color: white;
|
101 |
+
padding: 10px 20px;
|
102 |
+
border-radius: 50px;
|
103 |
+
font-weight: 600;
|
104 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
105 |
+
transition: all 0.3s ease;
|
106 |
+
}
|
107 |
+
|
108 |
+
.generate-btn:hover {
|
109 |
+
transform: translateY(-2px);
|
110 |
+
box-shadow: 0 6px 15px rgba(0,0,0,0.15);
|
111 |
+
}
|
112 |
+
|
113 |
+
.badge-container {
|
114 |
+
display: flex;
|
115 |
+
justify-content: center;
|
116 |
+
align-items: center;
|
117 |
+
gap: 8px;
|
118 |
+
flex-wrap: wrap;
|
119 |
+
margin-bottom: 1rem;
|
120 |
+
}
|
121 |
+
|
122 |
+
.badge {
|
123 |
+
display: inline-block;
|
124 |
+
padding: 0.25rem 0.75rem;
|
125 |
+
font-size: 0.875rem;
|
126 |
+
font-weight: 500;
|
127 |
+
line-height: 1.5;
|
128 |
+
text-align: center;
|
129 |
+
white-space: nowrap;
|
130 |
+
vertical-align: middle;
|
131 |
+
border-radius: 30px;
|
132 |
+
color: white;
|
133 |
+
background: #6c5ce7;
|
134 |
+
text-decoration: none;
|
135 |
+
}
|
136 |
+
|
137 |
+
.output-container {
|
138 |
+
background: rgba(243, 244, 246, 0.7);
|
139 |
+
border-radius: 10px;
|
140 |
+
padding: 1.5rem;
|
141 |
+
}
|
142 |
+
|
143 |
+
.slider-container label {
|
144 |
+
font-weight: 600;
|
145 |
+
margin-bottom: 0.5rem;
|
146 |
+
color: #4a5568;
|
147 |
+
}
|
148 |
+
"""
|
149 |
|
150 |
badges_text = r"""
|
151 |
+
<div class="badge-container">
|
152 |
+
<a href="https://github.com/bytedance/UNO" class="badge" style="background: #24292e;"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/bytedance/UNO" style="vertical-align: middle;"></a>
|
153 |
+
<a href="https://bytedance.github.io/UNO/" class="badge" style="background: #f1c40f; color: #333;"><img alt="Project Page" src="https://img.shields.io/badge/Project%20Page-UNO-yellow" style="vertical-align: middle;"></a>
|
154 |
+
<a href="https://arxiv.org/abs/2504.02160" class="badge" style="background: #b31b1b;"><img alt="arXiv" src="https://img.shields.io/badge/arXiv%20paper-UNO-b31b1b.svg" style="vertical-align: middle;"></a>
|
155 |
+
<a href="https://huggingface.co/bytedance-research/UNO" class="badge" style="background: #FF9D00;"><img src="https://img.shields.io/static/v1?label=%F0%9F%A4%97%20Hugging%20Face&message=Model&color=orange" style="vertical-align: middle;"></a>
|
156 |
+
<a href="https://huggingface.co/spaces/bytedance-research/UNO-FLUX" class="badge" style="background: #FF9D00;"><img src="https://img.shields.io/static/v1?label=%F0%9F%A4%97%20Hugging%20Face&message=demo&color=orange" style="vertical-align: middle;"></a>
|
157 |
</div>
|
158 |
""".strip()
|
159 |
|
160 |
+
with gr.Blocks(css=css) as demo:
|
161 |
+
gr.Markdown("# <div class='main-header'>UNO-FLUX Image Generator</div>")
|
162 |
gr.Markdown(badges_text)
|
163 |
+
|
164 |
with gr.Row():
|
165 |
+
with gr.Column(scale=3):
|
166 |
+
with gr.Box(elem_classes="container"):
|
167 |
+
prompt = gr.Textbox(
|
168 |
+
label="Prompt",
|
169 |
+
placeholder="Describe the image you want to generate...",
|
170 |
+
value="handsome woman in the city",
|
171 |
+
elem_classes="input-container"
|
172 |
+
)
|
173 |
+
|
174 |
+
gr.Markdown("### Reference Images")
|
175 |
+
with gr.Row(elem_classes="image-grid"):
|
176 |
+
image_prompt1 = gr.Image(label="Ref Img 1", visible=True, interactive=True, type="pil")
|
177 |
+
image_prompt2 = gr.Image(label="Ref Img 2", visible=True, interactive=True, type="pil")
|
178 |
+
image_prompt3 = gr.Image(label="Ref Img 3", visible=True, interactive=True, type="pil")
|
179 |
+
image_prompt4 = gr.Image(label="Ref Img 4", visible=True, interactive=True, type="pil")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
+
with gr.Row():
|
182 |
+
with gr.Column(scale=2):
|
183 |
+
with gr.Box(elem_classes="slider-container"):
|
184 |
+
width = gr.Slider(512, 2048, 512, step=16, label="Generation Width")
|
185 |
+
height = gr.Slider(512, 2048, 512, step=16, label="Generation Height")
|
186 |
+
|
187 |
+
with gr.Column(scale=1):
|
188 |
+
gr.Markdown("<div style='background: #f8f9fa; padding: 10px; border-radius: 8px; border-left: 4px solid #4776E6;'>📌 The model was trained on 512x512 resolution.<br>Sizes closer to 512 are more stable, higher sizes give better visual effects but are less stable.</div>")
|
189 |
+
|
190 |
+
with gr.Accordion("Advanced Options", open=False):
|
191 |
+
with gr.Row():
|
192 |
+
with gr.Column():
|
193 |
+
num_steps = gr.Slider(1, 50, 25, step=1, label="Number of steps")
|
194 |
+
with gr.Column():
|
195 |
+
guidance = gr.Slider(1.0, 5.0, 4.0, step=0.1, label="Guidance", interactive=True)
|
196 |
+
with gr.Column():
|
197 |
+
seed = gr.Number(-1, label="Seed (-1 for random)")
|
198 |
+
|
199 |
+
generate_btn = gr.Button("Generate", elem_classes="generate-btn")
|
200 |
+
|
201 |
+
with gr.Column(scale=2):
|
202 |
+
with gr.Box(elem_classes="output-container"):
|
203 |
+
gr.Markdown("### Generated Result")
|
204 |
+
output_image = gr.Image(label="Generated Image")
|
205 |
+
download_btn = gr.File(label="Download full-resolution", type="filepath", interactive=False)
|
206 |
|
207 |
|
208 |
inputs = [
|
|
|
218 |
example_text = gr.Text("", visible=False, label="Case For:")
|
219 |
examples = get_examples("./assets/examples")
|
220 |
|
221 |
+
with gr.Box(elem_classes="container"):
|
222 |
+
gr.Markdown("### <div style='text-align: center; margin-bottom: 1rem;'>Examples</div>")
|
223 |
+
gr.Examples(
|
224 |
+
examples=examples,
|
225 |
+
inputs=[
|
226 |
+
example_text, prompt,
|
227 |
+
image_prompt1, image_prompt2, image_prompt3, image_prompt4,
|
228 |
+
seed, output_image
|
229 |
+
],
|
230 |
+
)
|
231 |
|
232 |
return demo
|
233 |
|