Spaces:
Runtime error
Runtime error
Linoy Tsaban
commited on
Commit
·
1b706f6
1
Parent(s):
60f9c65
Update app.py
Browse files
app.py
CHANGED
@@ -142,14 +142,17 @@ def shuffle_lora(sdxl_loras, selected_lora=None):
|
|
142 |
else:
|
143 |
random_lora_index = random.randrange(0, len(sdxl_loras), 1)
|
144 |
print("random_lora_index in shuffle_lora: ", random_lora_index)
|
|
|
145 |
lora_repo = sdxl_loras[random_lora_index]["repo"]
|
146 |
lora_title = sdxl_loras[random_lora_index]["title"]
|
147 |
lora_desc = f"""#### LoRA used to edit this image:
|
148 |
## {lora_title}
|
149 |
by `{lora_repo.split('/')[0]}`
|
|
|
150 |
"""
|
151 |
lora_image = sdxl_loras[random_lora_index]["image"]
|
152 |
-
|
|
|
153 |
|
154 |
def check_if_removed(input_image):
|
155 |
if(input_image is None):
|
@@ -163,14 +166,17 @@ def block_if_removed(input_image):
|
|
163 |
|
164 |
def select_lora(selected_state: gr.SelectData, sdxl_loras):
|
165 |
random_lora_index = selected_state.index
|
|
|
166 |
lora_repo = sdxl_loras[random_lora_index]["repo"]
|
167 |
lora_title = sdxl_loras[random_lora_index]["title"]
|
168 |
lora_desc = f"""#### LoRA used to edit this image:
|
169 |
## {lora_title}
|
170 |
by `{lora_repo.split('/')[0]}`
|
|
|
171 |
"""
|
172 |
lora_image = sdxl_loras[random_lora_index]["image"]
|
173 |
-
|
|
|
174 |
|
175 |
|
176 |
def edit(sdxl_loras,
|
@@ -178,6 +184,7 @@ def edit(sdxl_loras,
|
|
178 |
wts, zs,
|
179 |
do_inversion,
|
180 |
random_lora_index,
|
|
|
181 |
progress=gr.Progress(track_tqdm=True)
|
182 |
):
|
183 |
show_share_button = gr.update(visible=True)
|
@@ -214,7 +221,7 @@ def edit(sdxl_loras,
|
|
214 |
|
215 |
latnets = wts[skip].expand(1, -1, -1, -1)
|
216 |
|
217 |
-
spooky_concept = random.choice([' spooky witch', ' spooky
|
218 |
print("spooky concept is: ", spooky_concept)
|
219 |
editing_prompt = [sdxl_loras[random_lora_index]["trigger_word"]+ spooky_concept]
|
220 |
reverse_editing_direction = [False]
|
@@ -293,7 +300,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
293 |
return True
|
294 |
|
295 |
gr.HTML("""<img style="margin: 0 auto; width: 220px;" src="https://i.imgur.com/zDcvSbg.png" alt="LEDITS SDXL LoRA Photobooth">""")
|
296 |
-
gr.HTML("""<img style="margin: 0 auto; width: 300px; margin-bottom: .5em;
|
297 |
with gr.Box(elem_id="total_box"):
|
298 |
gr.HTML(
|
299 |
"""
|
@@ -307,6 +314,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
307 |
gr_sdxl_loras = gr.State(value=sdxl_loras_raw)
|
308 |
gr_lora_index = gr.State()
|
309 |
gr_picked_lora = gr.State()
|
|
|
310 |
with gr.Row():
|
311 |
input_image = gr.Image(label="Input Image", interactive=True, source="webcam", height=512, width=512, elem_id="input_image")
|
312 |
with gr.Column(elem_classes="output_column") as output_column:
|
@@ -316,7 +324,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
316 |
sega_edited_image = gr.Image(label=f"LEDITS Edited Image", interactive=False, elem_id="output_image", height=512, width=512)
|
317 |
with gr.Column(visible=False) as buttons_area:
|
318 |
with gr.Row(elem_id="buttons_area"):
|
319 |
-
print_button = gr.HTML('<button onclick="window.print()" class="lg secondary svelte-cmf5ev" id="print" style="width: 100%;margin-bottom:0">
|
320 |
run_button = gr.Button("Regenerate with the same picture 🖼️🎲", elem_id="run_again")
|
321 |
|
322 |
|
@@ -332,14 +340,14 @@ with gr.Blocks(css="style.css") as demo:
|
|
332 |
choose_gallery.select(
|
333 |
fn=select_lora,
|
334 |
inputs=gr_sdxl_loras,
|
335 |
-
outputs=[gr_picked_lora, lora_image, lora_desc],
|
336 |
queue=False
|
337 |
)
|
338 |
|
339 |
run_button.click(
|
340 |
fn=shuffle_lora,
|
341 |
inputs=[gr_sdxl_loras, gr_picked_lora],
|
342 |
-
outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image],
|
343 |
queue=False
|
344 |
).then(
|
345 |
fn=edit,
|
@@ -347,7 +355,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
347 |
input_image,
|
348 |
wts, zs,
|
349 |
do_inversion,
|
350 |
-
gr_lora_index
|
351 |
],
|
352 |
outputs=[sega_edited_image, wts, zs, do_inversion, sega_edited_image, output_column, buttons_area]
|
353 |
).then(
|
@@ -373,7 +381,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
373 |
queue = False).then(
|
374 |
fn=shuffle_lora,
|
375 |
inputs=[gr_sdxl_loras, gr_picked_lora],
|
376 |
-
outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image],
|
377 |
queue=False
|
378 |
).then(
|
379 |
fn=edit,
|
@@ -381,7 +389,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
381 |
input_image,
|
382 |
wts, zs,
|
383 |
do_inversion,
|
384 |
-
gr_lora_index
|
|
|
385 |
],
|
386 |
outputs=[sega_edited_image, wts, zs, do_inversion, sega_edited_image, output_column, buttons_area]
|
387 |
).then(
|
@@ -389,21 +398,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
389 |
inputs=[gr_sdxl_loras, gr_lora_index, input_image, sega_edited_image],
|
390 |
queue=False
|
391 |
)
|
392 |
-
|
393 |
-
# <h1>Hugging Face at</h1>
|
394 |
-
# <img src="https://iccv2023.thecvf.com/img/LogoICCV23V04.svg" width="400" style="margin: 0 auto;" />
|
395 |
-
# ''', elem_id="iccv_logo")
|
396 |
|
397 |
-
demo.load(None,
|
398 |
-
_js="""async () => {
|
399 |
-
let gradioURL = new URL(window.self.location.href);
|
400 |
-
let params = new URLSearchParams(gradioURL.search);
|
401 |
-
|
402 |
-
if (!params.has('__theme') || params.get('__theme') !== 'dark') {
|
403 |
-
params.set('__theme', 'dark');
|
404 |
-
gradioURL.search = params.toString();
|
405 |
-
window.self.location.replace(gradioURL.toString());
|
406 |
-
}
|
407 |
-
}""")
|
408 |
demo.queue()
|
409 |
demo.launch()
|
|
|
142 |
else:
|
143 |
random_lora_index = random.randrange(0, len(sdxl_loras), 1)
|
144 |
print("random_lora_index in shuffle_lora: ", random_lora_index)
|
145 |
+
spooky_concept = random.choice([' spooky witch', ' spooky vampire', ' spooky werewolf', ' spooky ghost', ' spooky wizard', ' spooky pumpkin'])
|
146 |
lora_repo = sdxl_loras[random_lora_index]["repo"]
|
147 |
lora_title = sdxl_loras[random_lora_index]["title"]
|
148 |
lora_desc = f"""#### LoRA used to edit this image:
|
149 |
## {lora_title}
|
150 |
by `{lora_repo.split('/')[0]}`
|
151 |
+
### halloween concept: {spooky_concept}
|
152 |
"""
|
153 |
lora_image = sdxl_loras[random_lora_index]["image"]
|
154 |
+
|
155 |
+
return gr.update(), random_lora_index, lora_image, lora_desc, gr.update(visible=True), gr.update(height=369), spooky_concept
|
156 |
|
157 |
def check_if_removed(input_image):
|
158 |
if(input_image is None):
|
|
|
166 |
|
167 |
def select_lora(selected_state: gr.SelectData, sdxl_loras):
|
168 |
random_lora_index = selected_state.index
|
169 |
+
spooky_concept = random.choice([' spooky witch', ' spooky vampire', ' spooky werewolf', ' spooky ghost', ' spooky wizard', ' spooky pumpkin'])
|
170 |
lora_repo = sdxl_loras[random_lora_index]["repo"]
|
171 |
lora_title = sdxl_loras[random_lora_index]["title"]
|
172 |
lora_desc = f"""#### LoRA used to edit this image:
|
173 |
## {lora_title}
|
174 |
by `{lora_repo.split('/')[0]}`
|
175 |
+
### halloween concept: {spooky_concept}
|
176 |
"""
|
177 |
lora_image = sdxl_loras[random_lora_index]["image"]
|
178 |
+
|
179 |
+
return random_lora_index, lora_image, lora_desc, spooky_concept
|
180 |
|
181 |
|
182 |
def edit(sdxl_loras,
|
|
|
184 |
wts, zs,
|
185 |
do_inversion,
|
186 |
random_lora_index,
|
187 |
+
spooky_concept,
|
188 |
progress=gr.Progress(track_tqdm=True)
|
189 |
):
|
190 |
show_share_button = gr.update(visible=True)
|
|
|
221 |
|
222 |
latnets = wts[skip].expand(1, -1, -1, -1)
|
223 |
|
224 |
+
# spooky_concept = random.choice([' spooky witch', ' spooky vampire', ' spooky werewolf', ' spooky ghost', ' spooky wizard', ' spooky pumpkin'])
|
225 |
print("spooky concept is: ", spooky_concept)
|
226 |
editing_prompt = [sdxl_loras[random_lora_index]["trigger_word"]+ spooky_concept]
|
227 |
reverse_editing_direction = [False]
|
|
|
300 |
return True
|
301 |
|
302 |
gr.HTML("""<img style="margin: 0 auto; width: 220px;" src="https://i.imgur.com/zDcvSbg.png" alt="LEDITS SDXL LoRA Photobooth">""")
|
303 |
+
gr.HTML("""<img style="margin: 0 auto; width: 300px; margin-bottom: .5em;" src="https://i.imgur.com/hvZOBzY.png" alt="LEDITS SDXL LoRA Photobooth">""")
|
304 |
with gr.Box(elem_id="total_box"):
|
305 |
gr.HTML(
|
306 |
"""
|
|
|
314 |
gr_sdxl_loras = gr.State(value=sdxl_loras_raw)
|
315 |
gr_lora_index = gr.State()
|
316 |
gr_picked_lora = gr.State()
|
317 |
+
spooky_concept = gr.State()
|
318 |
with gr.Row():
|
319 |
input_image = gr.Image(label="Input Image", interactive=True, source="webcam", height=512, width=512, elem_id="input_image")
|
320 |
with gr.Column(elem_classes="output_column") as output_column:
|
|
|
324 |
sega_edited_image = gr.Image(label=f"LEDITS Edited Image", interactive=False, elem_id="output_image", height=512, width=512)
|
325 |
with gr.Column(visible=False) as buttons_area:
|
326 |
with gr.Row(elem_id="buttons_area"):
|
327 |
+
print_button = gr.HTML('<button onclick="window.print()" class="lg secondary svelte-cmf5ev" id="print" style="width: 100%;margin-bottom:0">Print 🖨️</button>')
|
328 |
run_button = gr.Button("Regenerate with the same picture 🖼️🎲", elem_id="run_again")
|
329 |
|
330 |
|
|
|
340 |
choose_gallery.select(
|
341 |
fn=select_lora,
|
342 |
inputs=gr_sdxl_loras,
|
343 |
+
outputs=[gr_picked_lora, lora_image, lora_desc, spooky_concept],
|
344 |
queue=False
|
345 |
)
|
346 |
|
347 |
run_button.click(
|
348 |
fn=shuffle_lora,
|
349 |
inputs=[gr_sdxl_loras, gr_picked_lora],
|
350 |
+
outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image, spooky_concept],
|
351 |
queue=False
|
352 |
).then(
|
353 |
fn=edit,
|
|
|
355 |
input_image,
|
356 |
wts, zs,
|
357 |
do_inversion,
|
358 |
+
gr_lora_index, spooky_concept
|
359 |
],
|
360 |
outputs=[sega_edited_image, wts, zs, do_inversion, sega_edited_image, output_column, buttons_area]
|
361 |
).then(
|
|
|
381 |
queue = False).then(
|
382 |
fn=shuffle_lora,
|
383 |
inputs=[gr_sdxl_loras, gr_picked_lora],
|
384 |
+
outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image, spooky_concept],
|
385 |
queue=False
|
386 |
).then(
|
387 |
fn=edit,
|
|
|
389 |
input_image,
|
390 |
wts, zs,
|
391 |
do_inversion,
|
392 |
+
gr_lora_index,
|
393 |
+
spooky_concept
|
394 |
],
|
395 |
outputs=[sega_edited_image, wts, zs, do_inversion, sega_edited_image, output_column, buttons_area]
|
396 |
).then(
|
|
|
398 |
inputs=[gr_sdxl_loras, gr_lora_index, input_image, sega_edited_image],
|
399 |
queue=False
|
400 |
)
|
401 |
+
|
|
|
|
|
|
|
402 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
demo.queue()
|
404 |
demo.launch()
|