artificialguybr commited on
Commit
b1b4f10
1 Parent(s): bb47310

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -15,25 +15,23 @@ base_model = "stabilityai/stable-diffusion-xl-base-1.0"
15
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.float16)
16
  pipe.to("cuda")
17
 
18
- def update_selection(selected_state: gr.SelectData):
19
- selected_lora_index = selected_state.index
20
- selected_lora = loras[selected_lora_index]
21
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
22
  lora_repo = selected_lora["repo"]
23
  updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo}) ✨"
24
  return (
25
  gr.update(placeholder=new_placeholder),
26
  updated_text,
27
- selected_state
28
  )
29
 
30
  @spaces.GPU
31
- def run_lora(prompt, negative_prompt, cfg_scale, steps, selected_state, scheduler):
32
- if not selected_state:
33
  raise gr.Error("You must select a LoRA before proceeding.")
34
 
35
- selected_lora_index = selected_state.index
36
- selected_lora = loras[selected_lora_index]
37
  lora_path = selected_lora["repo"]
38
  trigger_word = selected_lora["trigger_word"]
39
 
@@ -67,7 +65,7 @@ with gr.Blocks(css="custom.css") as app:
67
  "Special thanks to Hugging Face for their Diffusers library and Spaces platform."
68
  )
69
 
70
- selected_state = gr.State()
71
 
72
  with gr.Row():
73
  gallery = gr.Gallery(
@@ -92,11 +90,11 @@ with gr.Blocks(css="custom.css") as app:
92
  generate_button = gr.Button("Generate")
93
  result = gr.Image(label="Generated Image")
94
 
95
- gallery.select(update_selection, outputs=[prompt, selected_info, selected_state])
96
 
97
  generate_button.click(
98
  fn=run_lora,
99
- inputs=[prompt, negative_prompt, cfg_scale, steps, selected_state, scheduler],
100
  outputs=[result]
101
  )
102
 
 
15
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.float16)
16
  pipe.to("cuda")
17
 
18
+ def update_selection(evt: gr.SelectData):
19
+ selected_lora = loras[evt.index]
 
20
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
21
  lora_repo = selected_lora["repo"]
22
  updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo}) ✨"
23
  return (
24
  gr.update(placeholder=new_placeholder),
25
  updated_text,
26
+ evt.index
27
  )
28
 
29
  @spaces.GPU
30
+ def run_lora(prompt, negative_prompt, cfg_scale, steps, selected_index, scheduler):
31
+ if selected_index is None:
32
  raise gr.Error("You must select a LoRA before proceeding.")
33
 
34
+ selected_lora = loras[selected_index]
 
35
  lora_path = selected_lora["repo"]
36
  trigger_word = selected_lora["trigger_word"]
37
 
 
65
  "Special thanks to Hugging Face for their Diffusers library and Spaces platform."
66
  )
67
 
68
+ selected_index = gr.State(None)
69
 
70
  with gr.Row():
71
  gallery = gr.Gallery(
 
90
  generate_button = gr.Button("Generate")
91
  result = gr.Image(label="Generated Image")
92
 
93
+ gallery.select(update_selection, outputs=[prompt, selected_info, selected_index])
94
 
95
  generate_button.click(
96
  fn=run_lora,
97
+ inputs=[prompt, negative_prompt, cfg_scale, steps, selected_index, scheduler],
98
  outputs=[result]
99
  )
100