multimodalart HF staff commited on
Commit
4aecca8
·
1 Parent(s): 2bca82d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -135,14 +135,17 @@ def load_lora(sdxl_loras, random_lora_index, lora_scale = 1.0, progress=gr.Progr
135
 
136
 
137
  ## SEGA ##
138
- def shuffle_lora(sdxl_loras, selected_lora=None):
139
  print("selected_lora in shuffle_lora", selected_lora)
140
  if(selected_lora is not None):
141
  random_lora_index = selected_lora
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:
@@ -164,13 +167,16 @@ def block_if_removed(input_image):
164
  if(input_image is None):
165
  raise gr.Warning("Photo removed. Upload a new one!")
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
  prompt: {spooky_concept}
175
  by `{lora_repo.split('/')[0]}`
176
  """
@@ -328,7 +334,8 @@ with gr.Blocks(css="style.css") as demo:
328
  run_button = gr.Button("Regenerate with the same picture 🖼️🎲", elem_id="run_again")
329
 
330
 
331
- with gr.Accordion("Tired of randomizing? Pick your LoRA", open=False, elem_id="pick", ):
 
332
  choose_gallery = gr.Gallery(
333
  value=[(item["image"], item["title"]) for item in sdxl_loras_raw],
334
  allow_preview=False,
@@ -339,14 +346,14 @@ with gr.Blocks(css="style.css") as demo:
339
 
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(
@@ -380,7 +387,7 @@ with gr.Blocks(css="style.css") as demo:
380
  outputs = [do_inversion],
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(
 
135
 
136
 
137
  ## SEGA ##
138
+ def shuffle_lora(sdxl_loras, selected_lora=None, chosen_prompt):
139
  print("selected_lora in shuffle_lora", selected_lora)
140
  if(selected_lora is not None):
141
  random_lora_index = selected_lora
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
+ if(chosen_prompt):
146
+ spooky_concept = chosen_prompt
147
+ else:
148
+ spooky_concept = random.choice([' spooky witch', ' spooky vampire', ' spooky werewolf', ' spooky ghost', ' spooky wizard', ' spooky pumpkin', ' spooky wizard', 'spooky skeleton'])
149
  lora_repo = sdxl_loras[random_lora_index]["repo"]
150
  lora_title = sdxl_loras[random_lora_index]["title"]
151
  lora_desc = f"""#### LoRA used to edit this image:
 
167
  if(input_image is None):
168
  raise gr.Warning("Photo removed. Upload a new one!")
169
 
170
+ def select_lora(selected_state: gr.SelectData, sdxl_loras, chosen_prompt):
171
  random_lora_index = selected_state.index
172
+ if(chosen_prompt):
173
+ spooky_concept = chosen_prompt
174
+ else:
175
+ spooky_concept = random.choice([' spooky witch', ' spooky vampire', ' spooky werewolf', ' spooky ghost', ' spooky wizard', ' spooky pumpkin', ' spooky wizard', 'spooky skeleton'])
176
  lora_repo = sdxl_loras[random_lora_index]["repo"]
177
  lora_title = sdxl_loras[random_lora_index]["title"]
178
+ lora_desc = f"""#### LoRA used to edit this image:
179
+ ### {lora_title}
180
  prompt: {spooky_concept}
181
  by `{lora_repo.split('/')[0]}`
182
  """
 
334
  run_button = gr.Button("Regenerate with the same picture 🖼️🎲", elem_id="run_again")
335
 
336
 
337
+ with gr.Accordion("Tired of randomizing? Pick your prompt and LoRA", open=False, elem_id="pick", ):
338
+ choose_prompt = gr.Textbox(label="Spooky Prompt", value="")
339
  choose_gallery = gr.Gallery(
340
  value=[(item["image"], item["title"]) for item in sdxl_loras_raw],
341
  allow_preview=False,
 
346
 
347
  choose_gallery.select(
348
  fn=select_lora,
349
+ inputs=[gr_sdxl_loras, choose_prompt],
350
  outputs=[gr_picked_lora, lora_image, lora_desc, spooky_concept],
351
  queue=False
352
  )
353
 
354
  run_button.click(
355
  fn=shuffle_lora,
356
+ inputs=[gr_sdxl_loras, gr_picked_lora, choose_prompt],
357
  outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image, spooky_concept],
358
  queue=False
359
  ).then(
 
387
  outputs = [do_inversion],
388
  queue = False).then(
389
  fn=shuffle_lora,
390
+ inputs=[gr_sdxl_loras, gr_picked_lora, choose_prompt],
391
  outputs=[sega_edited_image, gr_lora_index, lora_image, lora_desc, loaded_lora, sega_edited_image, spooky_concept],
392
  queue=False
393
  ).then(