John6666 commited on
Commit
ef87b38
β€’
1 Parent(s): 3e8f15d

Upload 3 files

Browse files
Files changed (3) hide show
  1. all_models.py +13 -0
  2. app.py +9 -1
  3. externalmod.py +46 -0
all_models.py CHANGED
@@ -896,3 +896,16 @@ models = [
896
  "CompVis/stable-diffusion-v1-2", #208
897
  "CompVis/stable-diffusion-v1-1", #209
898
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
  "CompVis/stable-diffusion-v1-2", #208
897
  "CompVis/stable-diffusion-v1-1", #209
898
  ]
899
+
900
+
901
+ from externalmod import find_model_list
902
+
903
+ #models = find_model_list("Yntec", [], "", "last_modified", 20)
904
+
905
+ # Examples:
906
+ #models = ['yodayo-ai/kivotos-xl-2.0', 'yodayo-ai/holodayo-xl-2.1'] # specific models
907
+ #models = find_model_list("Yntec", [], "", "last_modified", 20) # Yntec's latest 20 models
908
+ #models = find_model_list("Yntec", ["anime"], "", "last_modified", 20) # Yntec's latest 20 models with 'anime' tag
909
+ #models = find_model_list("Yntec", [], "anime", "last_modified", 20) # Yntec's latest 20 models without 'anime' tag
910
+ #models = find_model_list("", [], "", "last_modified", 20) # latest 20 text-to-image models of huggingface
911
+ #models = find_model_list("", [], "", "downloads", 20) # monthly most downloaded 20 text-to-image models of huggingface
app.py CHANGED
@@ -40,6 +40,12 @@ def update_imgbox(choices):
40
  return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
41
 
42
 
 
 
 
 
 
 
43
  # https://huggingface.co/docs/api-inference/detailed_parameters
44
  # https://huggingface.co/docs/huggingface_hub/package_reference/inference_client
45
  async def infer(model_str, prompt, nprompt="", height=None, width=None, steps=None, cfg=None, timeout=inference_timeout):
@@ -114,7 +120,8 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', fill_width=True, css=CSS) as demo:
114
  steps = gr.Number(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
115
  cfg = gr.Number(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
116
  with gr.Row():
117
- gen_button = gr.Button(f'Generate up to {int(num_models)} images in up to 3 minutes total', scale=2)
 
118
  stop_button = gr.Button('Stop', variant='secondary', interactive=False, scale=1)
119
  gen_button.click(lambda: gr.update(interactive=True), None, stop_button)
120
  gr.Markdown("Scroll down to see more images and select models.", elem_classes="guide")
@@ -143,6 +150,7 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', fill_width=True, css=CSS) as demo:
143
  model_choice = gr.CheckboxGroup(models, label = f'Choose up to {int(num_models)} different models from the {len(models)} available!', value=default_models, interactive=True)
144
  model_choice.change(update_imgbox, model_choice, output)
145
  model_choice.change(extend_choices, model_choice, current_models)
 
146
 
147
  with gr.Tab('Single model'):
148
  with gr.Column(scale=2):
 
40
  return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
41
 
42
 
43
+ def random_choices():
44
+ import random
45
+ random.seed()
46
+ return random.choices(models, k = num_models)
47
+
48
+
49
  # https://huggingface.co/docs/api-inference/detailed_parameters
50
  # https://huggingface.co/docs/huggingface_hub/package_reference/inference_client
51
  async def infer(model_str, prompt, nprompt="", height=None, width=None, steps=None, cfg=None, timeout=inference_timeout):
 
120
  steps = gr.Number(label="Number of inference steps", info="If 0, the default value is used.", maximum=100, step=1, value=0)
121
  cfg = gr.Number(label="Guidance scale", info="If 0, the default value is used.", maximum=30.0, step=0.1, value=0)
122
  with gr.Row():
123
+ gen_button = gr.Button(f'Generate up to {int(num_models)} images in up to 3 minutes total', scale=3)
124
+ random_button = gr.Button(f'Random {int(num_models)} 🎲', variant='secondary', scale=1)
125
  stop_button = gr.Button('Stop', variant='secondary', interactive=False, scale=1)
126
  gen_button.click(lambda: gr.update(interactive=True), None, stop_button)
127
  gr.Markdown("Scroll down to see more images and select models.", elem_classes="guide")
 
150
  model_choice = gr.CheckboxGroup(models, label = f'Choose up to {int(num_models)} different models from the {len(models)} available!', value=default_models, interactive=True)
151
  model_choice.change(update_imgbox, model_choice, output)
152
  model_choice.change(extend_choices, model_choice, current_models)
153
+ random_button.click(random_choices, None, model_choice)
154
 
155
  with gr.Tab('Single model'):
156
  with gr.Column(scale=2):
externalmod.py CHANGED
@@ -532,3 +532,49 @@ def gr_Interface_load(
532
  **kwargs,
533
  ) -> Blocks:
534
  return load_blocks_from_repo(name, src, hf_token, alias)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
  **kwargs,
533
  ) -> Blocks:
534
  return load_blocks_from_repo(name, src, hf_token, alias)
535
+
536
+
537
+ def list_uniq(l):
538
+ return sorted(set(l), key=l.index)
539
+
540
+
541
+ def get_status(model_name: str):
542
+ from huggingface_hub import InferenceClient
543
+ client = InferenceClient(timeout=10)
544
+ return client.get_model_status(model_name)
545
+
546
+
547
+ def is_loadable(model_name: str, force_gpu: bool = False):
548
+ try:
549
+ status = get_status(model_name)
550
+ except Exception as e:
551
+ print(e)
552
+ print(f"Couldn't load {model_name}.")
553
+ return False
554
+ gpu_state = isinstance(status.compute_type, dict) and "gpu" in status.compute_type.keys()
555
+ if status is None or status.state not in ["Loadable", "Loaded"] or (force_gpu and not gpu_state):
556
+ print(f"Couldn't load {model_name}. Model state:'{status.state}', GPU:{gpu_state}")
557
+ return status is not None and status.state in ["Loadable", "Loaded"] and (not force_gpu or gpu_state)
558
+
559
+
560
+ def find_model_list(author: str="", tags: list[str]=[], not_tag="", sort: str="last_modified", limit: int=30, force_gpu=False, check_status=False):
561
+ from huggingface_hub import HfApi
562
+ api = HfApi()
563
+ default_tags = ["diffusers"]
564
+ if not sort: sort = "last_modified"
565
+ limit = limit * 20 if check_status and force_gpu else limit * 5
566
+ models = []
567
+ try:
568
+ model_infos = api.list_models(author=author, task="text-to-image",
569
+ tags=list_uniq(default_tags + tags), cardData=True, sort=sort, limit=limit)
570
+ except Exception as e:
571
+ print(f"Error: Failed to list models.")
572
+ print(e)
573
+ return models
574
+ for model in model_infos:
575
+ if not model.private and not model.gated:
576
+ loadable = is_loadable(model.id, force_gpu) if check_status else True
577
+ if not_tag and not_tag in model.tags or not loadable: continue
578
+ models.append(model.id)
579
+ if len(models) == limit: break
580
+ return models