Spaces:
Runtime error
Runtime error
beautifying info divs
Browse files
app.py
CHANGED
@@ -23,6 +23,12 @@ if is_gpu_associated:
|
|
23 |
else:
|
24 |
which_gpu = "CPU"
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def load_images_to_dataset(images, dataset_name):
|
27 |
|
28 |
if dataset_name == "":
|
@@ -208,41 +214,117 @@ def main(dataset_id,
|
|
208 |
|
209 |
css="""
|
210 |
#col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
"""
|
|
|
212 |
with gr.Blocks(css=css) as demo:
|
213 |
with gr.Column(elem_id="col-container"):
|
214 |
if is_shared_ui:
|
215 |
top_description = gr.HTML(f'''
|
216 |
<div class="gr-prose">
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
</div>
|
220 |
-
''')
|
221 |
else:
|
222 |
if(is_gpu_associated):
|
223 |
top_description = gr.HTML(f'''
|
224 |
<div class="gr-prose">
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
227 |
</div>
|
228 |
-
''')
|
229 |
else:
|
230 |
top_description = gr.HTML(f'''
|
231 |
<div class="gr-prose">
|
232 |
-
<h2
|
233 |
-
|
|
|
|
|
234 |
</div>
|
235 |
-
''')
|
|
|
236 |
gr.Markdown("# SD-XL Dreambooth LoRa Training UI 💭")
|
237 |
-
|
238 |
-
gr.
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
244 |
gr.Markdown("## Training ")
|
245 |
gr.Markdown("You can use an existing image dataset, find a dataset example here: [https://huggingface.co/datasets/diffusers/dog-example](https://huggingface.co/datasets/diffusers/dog-example) ;)")
|
|
|
246 |
with gr.Row():
|
247 |
dataset_id = gr.Textbox(label="Dataset ID", info="use one of your previously uploaded image datasets on your HF profile", placeholder="diffusers/dog-example")
|
248 |
instance_prompt = gr.Textbox(label="Concept prompt", info="concept prompt - use a unique, made up word to avoid collisions")
|
@@ -251,11 +333,17 @@ with gr.Blocks(css=css) as demo:
|
|
251 |
model_output_folder = gr.Textbox(label="Output model folder name", placeholder="lora-trained-xl-folder")
|
252 |
max_train_steps = gr.Number(label="Max Training Steps", value=500, precision=0, step=10)
|
253 |
checkpoint_steps = gr.Number(label="Checkpoints Steps", value=100, precision=0, step=10)
|
|
|
254 |
remove_gpu = gr.Checkbox(label="Remove GPU After Training", value=True)
|
255 |
train_button = gr.Button("Train !")
|
256 |
|
257 |
-
|
258 |
train_status = gr.Textbox(label="Training status")
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
load_btn.click(
|
261 |
fn = load_images_to_dataset,
|
|
|
23 |
else:
|
24 |
which_gpu = "CPU"
|
25 |
|
26 |
+
def check_upload_or_no(value):
|
27 |
+
if value is True:
|
28 |
+
return gr.update(visible=True)
|
29 |
+
else:
|
30 |
+
return gr.update(visible=False)
|
31 |
+
|
32 |
def load_images_to_dataset(images, dataset_name):
|
33 |
|
34 |
if dataset_name == "":
|
|
|
214 |
|
215 |
css="""
|
216 |
#col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
|
217 |
+
#upl-dataset-group {background-color: none!important;}
|
218 |
+
|
219 |
+
div#warning-ready {
|
220 |
+
background-color: #ecfdf5;
|
221 |
+
padding: 0 10px 5px;
|
222 |
+
margin: 20px 0;
|
223 |
+
}
|
224 |
+
div#warning-ready > .gr-prose > h2, div#warning-ready > .gr-prose > p {
|
225 |
+
color: #057857!important;
|
226 |
+
}
|
227 |
+
|
228 |
+
div#warning-duplicate {
|
229 |
+
background-color: #ebf5ff;
|
230 |
+
padding: 0 10px 5px;
|
231 |
+
margin: 20px 0;
|
232 |
+
}
|
233 |
+
|
234 |
+
div#warning-duplicate > .gr-prose > h2, div#warning-duplicate > .gr-prose > p {
|
235 |
+
color: #0f4592!important;
|
236 |
+
}
|
237 |
+
|
238 |
+
div#warning-duplicate strong {
|
239 |
+
color: #0f4592;
|
240 |
+
}
|
241 |
+
|
242 |
+
p.actions {
|
243 |
+
display: flex;
|
244 |
+
align-items: center;
|
245 |
+
margin: 20px 0;
|
246 |
+
}
|
247 |
+
|
248 |
+
div#warning-duplicate .actions a {
|
249 |
+
display: inline-block;
|
250 |
+
margin-right: 10px;
|
251 |
+
}
|
252 |
+
|
253 |
+
div#warning-setgpu {
|
254 |
+
background-color: #fff4eb;
|
255 |
+
padding: 0 10px 5px;
|
256 |
+
margin: 20px 0;
|
257 |
+
}
|
258 |
+
|
259 |
+
div#warning-setgpu > .gr-prose > h2, div#warning-setgpu > .gr-prose > p {
|
260 |
+
color: #92220f!important;
|
261 |
+
}
|
262 |
+
|
263 |
+
div#warning-setgpu a, div#warning-setgpu b {
|
264 |
+
color: #91230f;
|
265 |
+
}
|
266 |
+
|
267 |
+
button#load-dataset-btn{
|
268 |
+
min-height: 60px;
|
269 |
+
}
|
270 |
"""
|
271 |
+
|
272 |
with gr.Blocks(css=css) as demo:
|
273 |
with gr.Column(elem_id="col-container"):
|
274 |
if is_shared_ui:
|
275 |
top_description = gr.HTML(f'''
|
276 |
<div class="gr-prose">
|
277 |
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
278 |
+
Attention: this Space need to be duplicated to work</h2>
|
279 |
+
<p class="main-message">
|
280 |
+
To make it work, <strong>duplicate the Space</strong> and run it on your own profile using a <strong>private</strong> GPU (T4-small or A10G-small).<br />
|
281 |
+
A T4 costs <strong>US$0.60/h</strong>, so it should cost < US$1 to train most models.
|
282 |
+
</p>
|
283 |
+
<p class="actions">
|
284 |
+
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true">
|
285 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg-dark.svg" alt="Duplicate this Space" />
|
286 |
+
</a>
|
287 |
+
to start training your own image model
|
288 |
+
</p>
|
289 |
</div>
|
290 |
+
''', elem_id="warning-duplicate")
|
291 |
else:
|
292 |
if(is_gpu_associated):
|
293 |
top_description = gr.HTML(f'''
|
294 |
<div class="gr-prose">
|
295 |
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
296 |
+
You have successfully associated a {which_gpu} GPU to the SD-XL Training Space 🎉</h2>
|
297 |
+
<p>
|
298 |
+
You can now train your model! You will be billed by the minute from when you activated the GPU until when it is turned off.
|
299 |
+
</p>
|
300 |
</div>
|
301 |
+
''', elem_id="warning-ready")
|
302 |
else:
|
303 |
top_description = gr.HTML(f'''
|
304 |
<div class="gr-prose">
|
305 |
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
306 |
+
You have successfully duplicated the SD-XL Training Space 🎉</h2>
|
307 |
+
<p>There's only one step left before you can train your model: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a <b>T4-small or A10G-small GPU</b> to it (via the Settings tab)</a> and run the training below.
|
308 |
+
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
309 |
</div>
|
310 |
+
''', elem_id="warning-setgpu")
|
311 |
+
|
312 |
gr.Markdown("# SD-XL Dreambooth LoRa Training UI 💭")
|
313 |
+
|
314 |
+
upload_my_images = gr.Checkbox(label="Drop your training images ? (optional)", value=False)
|
315 |
+
gr.Markdown("Use this step to upload your training images and create a new dataset. If you already have a dataset stored on your HF profile, you can skip this step, and provide your dataset ID in the training `Datased ID` input below.")
|
316 |
+
|
317 |
+
with gr.Group(visible=False, elem_id="upl-dataset-group") as upload_group:
|
318 |
+
with gr.Row():
|
319 |
+
images = gr.File(file_types=["image"], label="Upload your images", file_count="multiple", interactive=True, visible=True)
|
320 |
+
with gr.Column():
|
321 |
+
new_dataset_name = gr.Textbox(label="Set new dataset name", placeholder="e.g.: my_awesome_dataset")
|
322 |
+
dataset_status = gr.Textbox(label="dataset status")
|
323 |
+
load_btn = gr.Button("Load images to new dataset", elem_id="load-dataset-btn")
|
324 |
+
|
325 |
gr.Markdown("## Training ")
|
326 |
gr.Markdown("You can use an existing image dataset, find a dataset example here: [https://huggingface.co/datasets/diffusers/dog-example](https://huggingface.co/datasets/diffusers/dog-example) ;)")
|
327 |
+
|
328 |
with gr.Row():
|
329 |
dataset_id = gr.Textbox(label="Dataset ID", info="use one of your previously uploaded image datasets on your HF profile", placeholder="diffusers/dog-example")
|
330 |
instance_prompt = gr.Textbox(label="Concept prompt", info="concept prompt - use a unique, made up word to avoid collisions")
|
|
|
333 |
model_output_folder = gr.Textbox(label="Output model folder name", placeholder="lora-trained-xl-folder")
|
334 |
max_train_steps = gr.Number(label="Max Training Steps", value=500, precision=0, step=10)
|
335 |
checkpoint_steps = gr.Number(label="Checkpoints Steps", value=100, precision=0, step=10)
|
336 |
+
|
337 |
remove_gpu = gr.Checkbox(label="Remove GPU After Training", value=True)
|
338 |
train_button = gr.Button("Train !")
|
339 |
|
|
|
340 |
train_status = gr.Textbox(label="Training status")
|
341 |
+
|
342 |
+
upload_my_images.change(
|
343 |
+
fn = check_upload_or_no,
|
344 |
+
inputs =[upload_my_images],
|
345 |
+
outputs = [upload_group]
|
346 |
+
)
|
347 |
|
348 |
load_btn.click(
|
349 |
fn = load_images_to_dataset,
|