ui_extra_networks_textual_inversion.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. from modules import ui_extra_networks, sd_hijack, shared
  3. from modules.ui_extra_networks import quote_js
  4. class ExtraNetworksPageTextualInversion(ui_extra_networks.ExtraNetworksPage):
  5. def __init__(self):
  6. super().__init__('Textual Inversion')
  7. self.allow_negative_prompt = True
  8. def refresh(self):
  9. sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True)
  10. def create_item(self, name, index=None):
  11. embedding = sd_hijack.model_hijack.embedding_db.word_embeddings.get(name)
  12. path, ext = os.path.splitext(embedding.filename)
  13. return {
  14. "name": name,
  15. "filename": embedding.filename,
  16. "preview": self.find_preview(path),
  17. "description": self.find_description(path),
  18. "search_term": self.search_terms_from_path(embedding.filename),
  19. "prompt": quote_js(embedding.name),
  20. "local_preview": f"{path}.preview.{shared.opts.samples_format}",
  21. "sort_keys": {'default': index, **self.get_sort_keys(embedding.filename)},
  22. }
  23. def list_items(self):
  24. for index, name in enumerate(sd_hijack.model_hijack.embedding_db.word_embeddings):
  25. yield self.create_item(name, index)
  26. def allowed_directories_for_previews(self):
  27. return list(sd_hijack.model_hijack.embedding_db.embedding_dirs)