John6666 commited on
Commit
053323f
·
verified ·
1 Parent(s): 08868a5

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. modutils.py +10 -13
app.py CHANGED
@@ -172,8 +172,11 @@ os.makedirs(directory_vaes, exist_ok=True)
172
  from modutils import (
173
  download_private_repo,
174
  get_private_lora_model_lists,
 
175
  get_model_id_list,
 
176
  list_uniq,
 
177
  get_tupled_embed_list,
178
  update_lora_dict,
179
  HF_LORA_ESSENTIAL_PRIVATE_REPO,
@@ -285,10 +288,19 @@ def get_embed_list(pipeline_name):
285
  return get_tupled_embed_list(embed_sdxl_list if pipeline_name == "StableDiffusionXLPipeline" else embed_list)
286
 
287
  def get_my_lora(link_url):
 
 
288
  for url in [url.strip() for url in link_url.split(',')]:
289
- if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
290
  download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
291
- update_lora_dict(f"./loras/{url.split('/')[-1]}")
 
 
 
 
 
 
 
292
  new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_model_list(directory_loras))
293
  new_lora_model_list.insert(0, "None")
294
 
 
172
  from modutils import (
173
  download_private_repo,
174
  get_private_lora_model_lists,
175
+ get_local_model_list,
176
  get_model_id_list,
177
+ escape_lora_basename,
178
  list_uniq,
179
+ list_sub,
180
  get_tupled_embed_list,
181
  update_lora_dict,
182
  HF_LORA_ESSENTIAL_PRIVATE_REPO,
 
288
  return get_tupled_embed_list(embed_sdxl_list if pipeline_name == "StableDiffusionXLPipeline" else embed_list)
289
 
290
  def get_my_lora(link_url):
291
+ from pathlib import Path
292
+ before = get_local_model_list(directory_loras)
293
  for url in [url.strip() for url in link_url.split(',')]:
294
+ if not Path(f"./loras/{url.split('/')[-1]}").exists():
295
  download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
296
+ after = get_local_model_list(directory_loras)
297
+ new_files = list_sub(after, before)
298
+ for file in new_files:
299
+ path = Path(file)
300
+ if path.exists():
301
+ new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
302
+ path.resolve().rename(new_path.resolve())
303
+ update_lora_dict(str(new_path))
304
  new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_model_list(directory_loras))
305
  new_lora_model_list.insert(0, "None")
306
 
modutils.py CHANGED
@@ -37,17 +37,14 @@ def change_interface_mode(mode: str):
37
  gr.update(visible=True), gr.update(value="Standard")
38
 
39
 
40
- def get_model_list(directory_path):
 
41
  model_list = []
42
- valid_extensions = {'.ckpt', '.pt', '.pth', '.safetensors', '.bin'}
43
-
44
- for filename in os.listdir(directory_path):
45
- if os.path.splitext(filename)[1] in valid_extensions:
46
- name_without_extension = os.path.splitext(filename)[0]
47
- file_path = os.path.join(directory_path, filename)
48
- # model_list.append((name_without_extension, file_path))
49
  model_list.append(file_path)
50
- # print('\033[34mFILE: ' + file_path + '\033[0m')
51
  return model_list
52
 
53
 
@@ -382,7 +379,7 @@ def get_lora_tupled_list(lora_model_list):
382
  from pathlib import Path
383
  if not lora_model_list: return []
384
  tupled_list = []
385
- local_models = set(get_model_list(directory_loras))
386
  for model in lora_model_list:
387
  if not model: continue
388
  basename = Path(model).stem
@@ -411,7 +408,7 @@ def set_lora_trigger(lora_gui: str):
411
  gr.update(value="", visible=False), gr.update(value="None", visible=True)
412
  path = Path(lora_gui)
413
  new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
414
- if not new_path.stem in lora_trigger_dict.keys() and not str(path) in set(get_private_lora_model_lists() + get_model_list(directory_loras)):
415
  return gr.update(value="", visible=False), gr.update(visible=False),\
416
  gr.update(value="", visible=False), gr.update(value="", visible=True)
417
  if not new_path.exists():
@@ -438,7 +435,7 @@ def set_lora_trigger(lora_gui: str):
438
  elif items[3]:
439
  md = f'[LoRA Model URL]({items[3]})'
440
  if tag and flag:
441
- new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_model_list(directory_loras))
442
  return gr.update(value=tag, label=label, visible=True), gr.update(visible=True),\
443
  gr.update(value=md, visible=True), gr.update(value=str(new_path), choices=get_lora_tupled_list(new_lora_model_list))
444
  elif tag:
@@ -477,7 +474,7 @@ def move_file_lora(filepaths):
477
  path.resolve().rename(newpath.resolve())
478
  update_lora_dict(str(newpath))
479
 
480
- new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_model_list(directory_loras))
481
  new_lora_model_list.insert(0, "None")
482
 
483
  return gr.update(
 
37
  gr.update(visible=True), gr.update(value="Standard")
38
 
39
 
40
+ def get_local_model_list(dir_path):
41
+ from pathlib import Path
42
  model_list = []
43
+ valid_extensions = ('.ckpt', '.pt', '.pth', '.safetensors', '.bin')
44
+ for file in Path(dir_path).glob("*"):
45
+ if file.suffix in valid_extensions:
46
+ file_path = str(Path(f"{dir_path}/{file.name}"))
 
 
 
47
  model_list.append(file_path)
 
48
  return model_list
49
 
50
 
 
379
  from pathlib import Path
380
  if not lora_model_list: return []
381
  tupled_list = []
382
+ local_models = set(get_local_model_list(directory_loras))
383
  for model in lora_model_list:
384
  if not model: continue
385
  basename = Path(model).stem
 
408
  gr.update(value="", visible=False), gr.update(value="None", visible=True)
409
  path = Path(lora_gui)
410
  new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
411
+ if not new_path.stem in lora_trigger_dict.keys() and not str(path) in set(get_private_lora_model_lists() + get_local_model_list(directory_loras)):
412
  return gr.update(value="", visible=False), gr.update(visible=False),\
413
  gr.update(value="", visible=False), gr.update(value="", visible=True)
414
  if not new_path.exists():
 
435
  elif items[3]:
436
  md = f'[LoRA Model URL]({items[3]})'
437
  if tag and flag:
438
+ new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_local_model_list(directory_loras))
439
  return gr.update(value=tag, label=label, visible=True), gr.update(visible=True),\
440
  gr.update(value=md, visible=True), gr.update(value=str(new_path), choices=get_lora_tupled_list(new_lora_model_list))
441
  elif tag:
 
474
  path.resolve().rename(newpath.resolve())
475
  update_lora_dict(str(newpath))
476
 
477
+ new_lora_model_list = list_uniq(get_private_lora_model_lists() + get_local_model_list(directory_loras))
478
  new_lora_model_list.insert(0, "None")
479
 
480
  return gr.update(