shared.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import os
  2. import sys
  3. import gradio as gr
  4. from modules import shared_cmd_options, shared_gradio_themes, options, shared_items, sd_models_types
  5. from modules.paths_internal import models_path, script_path, data_path, sd_configs_path, sd_default_config, sd_model_file, default_sd_model_file, extensions_dir, extensions_builtin_dir # noqa: F401
  6. from modules import util
  7. from typing import TYPE_CHECKING
  8. if TYPE_CHECKING:
  9. from modules import shared_state, styles, interrogate, shared_total_tqdm, memmon
  10. cmd_opts = shared_cmd_options.cmd_opts
  11. parser = shared_cmd_options.parser
  12. batch_cond_uncond = True # old field, unused now in favor of shared.opts.batch_cond_uncond
  13. parallel_processing_allowed = True
  14. styles_filename = cmd_opts.styles_file = cmd_opts.styles_file if len(cmd_opts.styles_file) > 0 else [os.path.join(data_path, 'styles.csv')]
  15. config_filename = cmd_opts.ui_settings_file
  16. hide_dirs = {"visible": not cmd_opts.hide_ui_dir_config}
  17. demo: gr.Blocks = None
  18. device: str = None
  19. weight_load_location: str = None
  20. xformers_available = False
  21. hypernetworks = {}
  22. loaded_hypernetworks = []
  23. state: 'shared_state.State' = None
  24. prompt_styles: 'styles.StyleDatabase' = None
  25. interrogator: 'interrogate.InterrogateModels' = None
  26. face_restorers = []
  27. options_templates: dict = None
  28. opts: options.Options = None
  29. restricted_opts: set[str] = None
  30. sd_model: sd_models_types.WebuiSdModel = None
  31. settings_components: dict = None
  32. """assigned from ui.py, a mapping on setting names to gradio components responsible for those settings"""
  33. tab_names = []
  34. latent_upscale_default_mode = "Latent"
  35. latent_upscale_modes = {
  36. "Latent": {"mode": "bilinear", "antialias": False},
  37. "Latent (antialiased)": {"mode": "bilinear", "antialias": True},
  38. "Latent (bicubic)": {"mode": "bicubic", "antialias": False},
  39. "Latent (bicubic antialiased)": {"mode": "bicubic", "antialias": True},
  40. "Latent (nearest)": {"mode": "nearest", "antialias": False},
  41. "Latent (nearest-exact)": {"mode": "nearest-exact", "antialias": False},
  42. }
  43. sd_upscalers = []
  44. clip_model = None
  45. progress_print_out = sys.stdout
  46. gradio_theme = gr.themes.Base()
  47. total_tqdm: 'shared_total_tqdm.TotalTQDM' = None
  48. mem_mon: 'memmon.MemUsageMonitor' = None
  49. options_section = options.options_section
  50. OptionInfo = options.OptionInfo
  51. OptionHTML = options.OptionHTML
  52. natural_sort_key = util.natural_sort_key
  53. listfiles = util.listfiles
  54. html_path = util.html_path
  55. html = util.html
  56. walk_files = util.walk_files
  57. ldm_print = util.ldm_print
  58. reload_gradio_theme = shared_gradio_themes.reload_gradio_theme
  59. list_checkpoint_tiles = shared_items.list_checkpoint_tiles
  60. refresh_checkpoints = shared_items.refresh_checkpoints
  61. list_samplers = shared_items.list_samplers
  62. reload_hypernetworks = shared_items.reload_hypernetworks
  63. hf_endpoint = os.getenv('HF_ENDPOINT', 'https://huggingface.co')