Unverified Commit c8c48640 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub
Browse files

Merge pull request #12426 from AUTOMATIC1111/split_shared

Split shared.py into multiple files
parents 2617598b 386245a2
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ import contextlib
from functools import lru_cache

import torch
from modules import errors
from modules import errors, shared

if sys.platform == "darwin":
    from modules import mac_specific
@@ -17,8 +17,6 @@ def has_mps() -> bool:


def get_cuda_device_string():
    from modules import shared

    if shared.cmd_opts.device_id is not None:
        return f"cuda:{shared.cmd_opts.device_id}"

@@ -40,8 +38,6 @@ def get_optimal_device():


def get_device_for(task):
    from modules import shared

    if task in shared.cmd_opts.use_cpu:
        return cpu

@@ -97,8 +93,6 @@ nv_rng = None


def autocast(disable=False):
    from modules import shared

    if disable:
        return contextlib.nullcontext()

@@ -117,8 +111,6 @@ class NansException(Exception):


def test_for_nans(x, where):
    from modules import shared

    if shared.cmd_opts.disable_nan_check:
        return

+1 −3
Original line number Diff line number Diff line
import os
import threading

from modules import shared, errors, cache
from modules import shared, errors, cache, scripts
from modules.gitpython_hack import Repo
from modules.paths_internal import extensions_dir, extensions_builtin_dir, script_path  # noqa: F401

@@ -90,8 +90,6 @@ class Extension:
        self.have_info_from_repo = True

    def list_files(self, subdir, extension):
        from modules import scripts

        dirpath = os.path.join(self.path, subdir)
        if not os.path.isdir(dirpath):
            return []
+1 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import re

import gradio as gr
from modules.paths import data_path
from modules import shared, ui_tempdir, script_callbacks
from modules import shared, ui_tempdir, script_callbacks, processing
from PIL import Image

re_param_code = r'\s*([\w ]+):\s*("(?:\\"[^,]|\\"|\\|[^\"])+"|[^,]*)(?:,|$)'
@@ -198,7 +198,6 @@ def restore_old_hires_fix_params(res):
    height = int(res.get("Size-2", 512))

    if firstpass_width == 0 or firstpass_height == 0:
        from modules import processing
        firstpass_width, firstpass_height = processing.old_hires_fix_first_pass_dimensions(width, height)

    res['Size-1'] = firstpass_width
+16 −12
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ from modules import sd_samplers, shared, script_callbacks, errors
from modules.paths_internal import roboto_ttf_file
from modules.shared import opts

import modules.sd_vae as sd_vae

LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS)


@@ -342,16 +340,6 @@ def sanitize_filename_part(text, replace_spaces=True):


class FilenameGenerator:
    def get_vae_filename(self): #get the name of the VAE file.
        if sd_vae.loaded_vae_file is None:
            return "NoneType"
        file_name = os.path.basename(sd_vae.loaded_vae_file)
        split_file_name = file_name.split('.')
        if len(split_file_name) > 1 and split_file_name[0] == '':
            return split_file_name[1] # if the first character of the filename is "." then [1] is obtained.
        else:
            return split_file_name[0]

    replacements = {
        'seed': lambda self: self.seed if self.seed is not None else '',
        'seed_first': lambda self: self.seed if self.p.batch_size == 1 else self.p.all_seeds[0],
@@ -391,6 +379,22 @@ class FilenameGenerator:
        self.image = image
        self.zip = zip

    def get_vae_filename(self):
        """Get the name of the VAE file."""

        import modules.sd_vae as sd_vae

        if sd_vae.loaded_vae_file is None:
            return "NoneType"

        file_name = os.path.basename(sd_vae.loaded_vae_file)
        split_file_name = file_name.split('.')
        if len(split_file_name) > 1 and split_file_name[0] == '':
            return split_file_name[1]  # if the first character of the filename is "." then [1] is obtained.
        else:
            return split_file_name[0]


    def hasprompt(self, *args):
        lower = self.prompt.lower()
        if self.p is None or self.prompt is None:
+1 −2
Original line number Diff line number Diff line
import json
import os

from modules import errors
from modules import errors, scripts

localizations = {}

@@ -16,7 +16,6 @@ def list_localizations(dirname):

        localizations[fn] = os.path.join(dirname, file)

    from modules import scripts
    for file in scripts.list_scripts("localizations", ".json"):
        fn, ext = os.path.splitext(file.filename)
        localizations[fn] = file.path
Loading