jbilcke-hf HF Staff commited on
Commit
b5a40cb
·
verified ·
1 Parent(s): d4a038b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -19
app.py CHANGED
@@ -5,7 +5,6 @@ import timm
5
  import time
6
  from huggingface_hub import hf_hub_download
7
  from safetensors.torch import load_file
8
- from share_btn import community_icon_html, loading_icon_html, share_js
9
  from cog_sdxl_dataset_and_utils import TokenEmbeddingsHandler
10
 
11
  import lora
@@ -148,13 +147,7 @@ pipe.to(device)
148
 
149
  last_lora = ""
150
  last_fused = False
151
- js = '''
152
- var button = document.getElementById('button');
153
- // Add a click event listener to the button
154
- button.addEventListener('click', function() {
155
- element.classList.add('selected');
156
- });
157
- '''
158
  def update_selection(selected_state: gr.SelectData, sdxl_loras, face_strength, image_strength, weight, depth_control_scale, negative, is_new=False):
159
  lora_repo = sdxl_loras[selected_state.index]["repo"]
160
  new_placeholder = "Type a prompt to use your selected LoRA"
@@ -349,7 +342,7 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
349
 
350
  st = time.time()
351
  image = generate_image(prompt, negative, face_emb, face_image, face_kps, image_strength, guidance_scale, face_strength, depth_control_scale, repo_name, full_path_lora, lora_scale, sdxl_loras, selected_state_index, st)
352
- return image, gr.update(visible=True)
353
 
354
  def shuffle_gallery(sdxl_loras):
355
  random.shuffle(sdxl_loras)
@@ -368,7 +361,7 @@ def swap_gallery(order, sdxl_loras):
368
  def deselect():
369
  return gr.Gallery(selected_index=None)
370
 
371
- with gr.Blocks(css="custom.css") as demo:
372
  gr_sdxl_loras = gr.State(value=sdxl_loras_raw)
373
  title = gr.HTML(
374
  """<h1><img src="https://i.imgur.com/DVoGw04.png">
@@ -409,10 +402,7 @@ with gr.Blocks(css="custom.css") as demo:
409
  result = gr.Image(
410
  interactive=False, label="Generated Image", elem_id="result-image"
411
  )
412
- with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
413
- community_icon = gr.HTML(community_icon_html)
414
- loading_icon = gr.HTML(loading_icon_html)
415
- share_button = gr.Button("Share to community", elem_id="share-btn")
416
  with gr.Accordion("Advanced options", open=False):
417
  negative = gr.Textbox(label="Negative Prompt")
418
 
@@ -463,7 +453,7 @@ with gr.Blocks(css="custom.css") as demo:
463
  ).success(
464
  fn=run_lora,
465
  inputs=[photo, prompt, negative, weight, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, gr_sdxl_loras],
466
- outputs=[result, share_group],
467
  )
468
  button.click(
469
  fn=check_selected,
@@ -473,9 +463,9 @@ with gr.Blocks(css="custom.css") as demo:
473
  ).success(
474
  fn=run_lora,
475
  inputs=[photo, prompt, negative, weight, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, gr_sdxl_loras],
476
- outputs=[result, share_group],
477
  )
478
- share_button.click(None, [], [], js=share_js)
479
- demo.load(fn=classify_gallery, inputs=[gr_sdxl_loras], outputs=[gallery, gr_sdxl_loras], queue=False, js=js)
480
  demo.queue(max_size=20)
481
- demo.launch(share=True)
 
5
  import time
6
  from huggingface_hub import hf_hub_download
7
  from safetensors.torch import load_file
 
8
  from cog_sdxl_dataset_and_utils import TokenEmbeddingsHandler
9
 
10
  import lora
 
147
 
148
  last_lora = ""
149
  last_fused = False
150
+
 
 
 
 
 
 
151
  def update_selection(selected_state: gr.SelectData, sdxl_loras, face_strength, image_strength, weight, depth_control_scale, negative, is_new=False):
152
  lora_repo = sdxl_loras[selected_state.index]["repo"]
153
  new_placeholder = "Type a prompt to use your selected LoRA"
 
342
 
343
  st = time.time()
344
  image = generate_image(prompt, negative, face_emb, face_image, face_kps, image_strength, guidance_scale, face_strength, depth_control_scale, repo_name, full_path_lora, lora_scale, sdxl_loras, selected_state_index, st)
345
+ return image
346
 
347
  def shuffle_gallery(sdxl_loras):
348
  random.shuffle(sdxl_loras)
 
361
  def deselect():
362
  return gr.Gallery(selected_index=None)
363
 
364
+ with gr.Blocks() as demo:
365
  gr_sdxl_loras = gr.State(value=sdxl_loras_raw)
366
  title = gr.HTML(
367
  """<h1><img src="https://i.imgur.com/DVoGw04.png">
 
402
  result = gr.Image(
403
  interactive=False, label="Generated Image", elem_id="result-image"
404
  )
405
+
 
 
 
406
  with gr.Accordion("Advanced options", open=False):
407
  negative = gr.Textbox(label="Negative Prompt")
408
 
 
453
  ).success(
454
  fn=run_lora,
455
  inputs=[photo, prompt, negative, weight, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, gr_sdxl_loras],
456
+ outputs=[result],
457
  )
458
  button.click(
459
  fn=check_selected,
 
463
  ).success(
464
  fn=run_lora,
465
  inputs=[photo, prompt, negative, weight, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, gr_sdxl_loras],
466
+ outputs=[result],
467
  )
468
+
469
+ demo.load(fn=classify_gallery, inputs=[gr_sdxl_loras], outputs=[gallery, gr_sdxl_loras], queue=False)
470
  demo.queue(max_size=20)
471
+ demo.launch()