# pip install html5print requests huggingface-hub Pillow import argparse import datetime import os import shutil import sys from urllib import request as ulreq import requests from huggingface_hub import HfApi from PIL import ImageFile parser = argparse.ArgumentParser() parser.add_argument('out_file', nargs='?', help='file to save to', default='stable-diffusion-textual-inversion-models.html') args = parser.parse_args() print('Will save to file:', args.out_file) # Init some stuff before saving the time api = HfApi() models_list = [] # Save the time now before we do the hard work dt = datetime.datetime.now() tz = dt.astimezone().tzname() # Get list of models under the sd-concepts-library organization for model in api.list_models(author="sd-concepts-library"): models_list.append(model.modelId.replace('sd-concepts-library/', '')) models_list.sort() html_struct = f""" Stable Diffusion Textual Inversion Embeddings

Stable Diffusion Textual Inversion Embeddings

Page updates automatically daily. Last updated {dt.strftime("%A %B %d, %Y")}.

Browser for the HuggingFace textual inversion library. There are currently {len(models_list)} textual inversion embeddings in sd-concepts-library. These are meant to be used with AUTOMATIC1111's SD WebUI.

Embeddings are downloaded straight from the HuggingFace repositories. The images displayed are the inputs, not the outputs. Want to quickly test concepts? Try the Stable Diffusion Conceptualizer on HuggingFace. More info on textual inversion.



""" i = 1 for model_name in models_list: # For testing # if i == 4: # break print(f'{i}/{len(models_list)} -> {model_name}') html_struct = html_struct + f'

{model_name}

' # Get the concept images from the huggingface repo restricted = False try: files = api.list_repo_files( repo_id=f'sd-concepts-library/{model_name}') concept_images = [i for i in files if i.startswith('concept_images/')] except requests.exceptions.HTTPError: # Sometimes an author will require you to share your contact info to gain access restricted = True if restricted: html_struct = html_struct + f"""

{model_name} is restricted and you must share your contact information to view this repository. View Repository

""" else: html_struct = html_struct + f"""

View Repository

""" # Most repos have 3 concept images but some have more or less # We gotta make sure only 3 are shown img_count = 3 if len(concept_images) < 3: img_count = len(concept_images) for x in range(img_count): html_struct = html_struct + f"""
""" html_struct = html_struct + '
' i = i + 1 html_struct = html_struct + """
""" f = open(args.out_file, 'w', encoding='utf-8') f.write(html_struct) f.close()