John6666 commited on
Commit
7bc191d
·
verified ·
1 Parent(s): ec8a3fb

Upload modutils.py

Browse files
Files changed (1) hide show
  1. modutils.py +14 -5
modutils.py CHANGED
@@ -20,6 +20,10 @@ def get_user_agent():
20
  return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
21
 
22
 
 
 
 
 
23
  def list_uniq(l):
24
  return sorted(set(l), key=l.index)
25
 
@@ -547,10 +551,13 @@ def get_lora_info(lora_path: str):
547
  tag = ""
548
  label = ""
549
  md = "None"
550
- if not lora_path or lora_path == "None": return is_valid, label, tag, md
 
 
551
  path = Path(lora_path)
552
  new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
553
- if not to_lora_key(str(new_path)) in loras_dict.keys() and not str(path) in set(all_lora_list):
 
554
  return tag, label, tag, md
555
  if not new_path.exists():
556
  download_private_file_from_somewhere(str(path), True)
@@ -729,11 +736,12 @@ def get_civitai_info(path):
729
  try:
730
  r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
731
  except Exception as e:
 
732
  return default
733
  else:
734
  if not r.ok: return None
735
  json = r.json()
736
- if not 'baseModel' in json:
737
  civitai_not_exists_list.append(path)
738
  return default
739
  items = []
@@ -762,16 +770,17 @@ def search_lora_on_civitai(query: str, allow_model: list[str] = ["Pony", "SDXL 1
762
  try:
763
  r = session.get(base_url, params=params, headers=headers, stream=True, timeout=(3.0, 30))
764
  except Exception as e:
 
765
  return None
766
  else:
767
  if not r.ok: return None
768
  json = r.json()
769
- if not 'items' in json: return None
770
  items = []
771
  for j in json['items']:
772
  for model in j['modelVersions']:
773
  item = {}
774
- if not model['baseModel'] in set(allow_model): continue
775
  item['name'] = j['name']
776
  item['creator'] = j['creator']['username']
777
  item['tags'] = j['tags']
 
20
  return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
21
 
22
 
23
+ def to_list(s):
24
+ return [x.strip() for x in s.split(",") if not s == ""]
25
+
26
+
27
  def list_uniq(l):
28
  return sorted(set(l), key=l.index)
29
 
 
551
  tag = ""
552
  label = ""
553
  md = "None"
554
+ if not lora_path or lora_path == "None":
555
+ print("LoRA file not found.")
556
+ return is_valid, label, tag, md
557
  path = Path(lora_path)
558
  new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
559
+ if not to_lora_key(str(new_path)) in loras_dict.keys() and str(path) not in set(get_all_lora_list()):
560
+ print("LoRA file is not registered.")
561
  return tag, label, tag, md
562
  if not new_path.exists():
563
  download_private_file_from_somewhere(str(path), True)
 
736
  try:
737
  r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
738
  except Exception as e:
739
+ print(e)
740
  return default
741
  else:
742
  if not r.ok: return None
743
  json = r.json()
744
+ if 'baseModel' not in json:
745
  civitai_not_exists_list.append(path)
746
  return default
747
  items = []
 
770
  try:
771
  r = session.get(base_url, params=params, headers=headers, stream=True, timeout=(3.0, 30))
772
  except Exception as e:
773
+ print(e)
774
  return None
775
  else:
776
  if not r.ok: return None
777
  json = r.json()
778
+ if 'items' not in json: return None
779
  items = []
780
  for j in json['items']:
781
  for model in j['modelVersions']:
782
  item = {}
783
+ if model['baseModel'] not in set(allow_model): continue
784
  item['name'] = j['name']
785
  item['creator'] = j['creator']['username']
786
  item['tags'] = j['tags']