amisima commited on
Commit
0c99749
·
verified ·
1 Parent(s): 8769b0f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -6
app.py CHANGED
@@ -4952,7 +4952,8 @@ def _library_pool():
4952
  pool = []
4953
  for choice in LORA_CHOICES:
4954
  if choice and choice != "(None)":
4955
- pool.append({"name": choice, "builtin": True, "trigger": "", "strength": 1.0})
 
4956
  try:
4957
  data = lora_library.load_library()
4958
  except Exception as error: # noqa: BLE001
@@ -5086,6 +5087,33 @@ def _slot_updates(items, slots=2):
5086
  return updates
5087
 
5088
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5089
  with gr.Blocks(delete_cache=(3600, 259200)) as demo:
5090
  gr.HTML("<style>" + CSS + "</style>")
5091
  gr.HTML(HERO)
@@ -5170,6 +5198,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
5170
  info="Two at a time is the limit. Every tick refills the slots and "
5171
  "puts the trigger words into the prompt.",
5172
  )
 
5173
  basic_shortlist = gr.State([])
5174
 
5175
  with gr.Accordion("🖋️ Help me write the prompt", open=False,
@@ -6409,7 +6438,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
6409
  "<div class='status-idle'>Nothing matched these words, in the built-in "
6410
  "list or the library. The prompt is still written.</div>",
6411
  gr.update(), gr.update(value=[])]
6412
- + _slot_updates([])
6413
  )
6414
  progress(0.6, desc="asking which of them fits")
6415
  chosen = _ask_which_loras(space_id, prompt_text, shortlist) or [0]
@@ -6422,7 +6451,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
6422
  _basic_note(picks, f" Picked out of {len(shortlist)} that matched."),
6423
  gr.update(value=_retune_triggers(prompt_text, shortlist, linked)),
6424
  gr.update(value=built)]
6425
- + _slot_updates(linked)
6426
  )
6427
 
6428
  def _basic_swap(ticked, shortlist, prompt_text):
@@ -6435,7 +6464,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
6435
  [_basic_note(picks, extra),
6436
  gr.update(value=_retune_triggers(prompt_text, shortlist, linked)),
6437
  gr.update(value=built)]
6438
- + _slot_updates(linked)
6439
  )
6440
 
6441
  basic_btn.click(
@@ -6448,7 +6477,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
6448
  fn=_basic_choose,
6449
  inputs=[prompt_input, pb_space],
6450
  outputs=([basic_pick, basic_shortlist, basic_status, prompt_input, simple_lora]
6451
- + _BASIC_SLOTS),
6452
  ).then(
6453
  fn=_read_effects, inputs=_LORA_READ_IN, outputs=_LORA_READ_OUT,
6454
  )
@@ -6460,7 +6489,7 @@ with gr.Blocks(delete_cache=(3600, 259200)) as demo:
6460
  _tick_event(
6461
  fn=_basic_swap,
6462
  inputs=[basic_pick, basic_shortlist, prompt_input],
6463
- outputs=[basic_status, prompt_input, simple_lora] + _BASIC_SLOTS,
6464
  ).then(
6465
  fn=_read_effects, inputs=_LORA_READ_IN, outputs=_LORA_READ_OUT,
6466
  )
 
4952
  pool = []
4953
  for choice in LORA_CHOICES:
4954
  if choice and choice != "(None)":
4955
+ pool.append({"name": choice, "builtin": True, "trigger": "",
4956
+ "strength": 1.0, "url": ""})
4957
  try:
4958
  data = lora_library.load_library()
4959
  except Exception as error: # noqa: BLE001
 
5087
  return updates
5088
 
5089
 
5090
+
5091
+
5092
+ def _pick_links(shortlist, picks):
5093
+ """A link to each candidate's own page, so a name can be read up on before it is
5094
+ ticked. The page is usually saved with the entry; when it is not, the download link
5095
+ on its own does not say which model it belongs to, so the version is resolved once
5096
+ through the API and remembered."""
5097
+ if not shortlist:
5098
+ return ""
5099
+ # Keyed on the link, falling back to the name: the built-in entries carry no link
5100
+ # at all, and keying those on a missing value ticks every one of them at once.
5101
+ chosen = {str(item.get("url") or item.get("name")) for item in (picks or [])}
5102
+ rows = []
5103
+ for index, item in enumerate(shortlist, start=1):
5104
+ name = str(item.get("name") or "").strip() or f"lora {index}"
5105
+ mark = "\u2705" if str(item.get("url") or item.get("name")) in chosen else "\u25ab\ufe0f"
5106
+ page = ""
5107
+ if not item.get("builtin"):
5108
+ try:
5109
+ page = lora_library._entry_page_url(item, resolve=True)
5110
+ except Exception: # noqa: BLE001
5111
+ page = str(item.get("page") or "").strip()
5112
+ rows.append(f"{mark} {index}. [{name}]({page})" if page
5113
+ else f"{mark} {index}. {name}")
5114
+ return "**\U0001f517 open a lora's own page** \n" + " \n".join(rows)
5115
+
5116
+
5117
  with gr.Blocks(delete_cache=(3600, 259200)) as demo:
5118
  gr.HTML("<style>" + CSS + "</style>")
5119
  gr.HTML(HERO)
 
5198
  info="Two at a time is the limit. Every tick refills the slots and "
5199
  "puts the trigger words into the prompt.",
5200
  )
5201
+ basic_links = gr.Markdown("")
5202
  basic_shortlist = gr.State([])
5203
 
5204
  with gr.Accordion("🖋️ Help me write the prompt", open=False,
 
6438
  "<div class='status-idle'>Nothing matched these words, in the built-in "
6439
  "list or the library. The prompt is still written.</div>",
6440
  gr.update(), gr.update(value=[])]
6441
+ + _slot_updates([]) + [gr.update(value="")]
6442
  )
6443
  progress(0.6, desc="asking which of them fits")
6444
  chosen = _ask_which_loras(space_id, prompt_text, shortlist) or [0]
 
6451
  _basic_note(picks, f" Picked out of {len(shortlist)} that matched."),
6452
  gr.update(value=_retune_triggers(prompt_text, shortlist, linked)),
6453
  gr.update(value=built)]
6454
+ + _slot_updates(linked) + [gr.update(value=_pick_links(shortlist, picks))]
6455
  )
6456
 
6457
  def _basic_swap(ticked, shortlist, prompt_text):
 
6464
  [_basic_note(picks, extra),
6465
  gr.update(value=_retune_triggers(prompt_text, shortlist, linked)),
6466
  gr.update(value=built)]
6467
+ + _slot_updates(linked) + [gr.update(value=_pick_links(shortlist, picks))]
6468
  )
6469
 
6470
  basic_btn.click(
 
6477
  fn=_basic_choose,
6478
  inputs=[prompt_input, pb_space],
6479
  outputs=([basic_pick, basic_shortlist, basic_status, prompt_input, simple_lora]
6480
+ + _BASIC_SLOTS + [basic_links]),
6481
  ).then(
6482
  fn=_read_effects, inputs=_LORA_READ_IN, outputs=_LORA_READ_OUT,
6483
  )
 
6489
  _tick_event(
6490
  fn=_basic_swap,
6491
  inputs=[basic_pick, basic_shortlist, prompt_input],
6492
+ outputs=[basic_status, prompt_input, simple_lora] + _BASIC_SLOTS + [basic_links],
6493
  ).then(
6494
  fn=_read_effects, inputs=_LORA_READ_IN, outputs=_LORA_READ_OUT,
6495
  )