import argparse import datetime import os import shutil import sys from urllib import request as ulreq from bs4 import BeautifulSoup 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 Models

Stable Diffusion Textual Inversion Models

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

Browser for the HuggingFace textual inversion library. There are currently {len(models_list)} textual inversion models in sd-concepts-library.

Models 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 + """
""" # Load the HTML into bs4 so we can format it soup = BeautifulSoup(html_struct, "html.parser") f = open(args.out_file, 'w', encoding='utf-8') f.write(str(soup.prettify())) f.close()