Skip to content

Commit

Permalink
Removes database and settings manager
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ffl35 committed Jan 17, 2024
1 parent 3fa8bc6 commit c43fb15
Show file tree
Hide file tree
Showing 46 changed files with 742 additions and 1,074 deletions.
50 changes: 27 additions & 23 deletions src/airunner/aihandler/auto_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from airunner.aihandler.logger import Logger as logger
from airunner.data.managers import SettingsManager
from airunner.windows.main.pipeline_mixin import PipelineMixin
from airunner.windows.main.settings_mixin import SettingsMixin


class AutoImport:

class AutoImport(
SettingsMixin,
PipelineMixin
):
def __init__(self, requested_action, pipeline_action="", category=None):
self.__class__ = AutoImport.class_object(requested_action, pipeline_action, category)

Expand Down Expand Up @@ -59,24 +64,23 @@ def class_object(
category = category if category else model_data["category"]
if pipeline_action == "txt2img" and requested_action == "img2img":
pipeline_action = "img2img"
settings_manager = SettingsManager()
with settings_manager.available_pipeline_by_section(pipeline_action, version, category) as pipeline:
try:
if single_file and pipeline.singlefile_classname != "" and pipeline.singlefile_classname is not None:
classname = pipeline.singlefile_classname
else:
classname = pipeline.classname
except KeyError:
logger.error(f"Failed to find classname for pipeline_action {pipeline_action} {version} {category}")
return
except AttributeError as e:
logger.error(f"Failed to find classname for pipeline_action {pipeline_action} {version} {category}")
return
pipeline_classname = classname.split(".")
module = None
for index, module_name in enumerate(pipeline_classname):
if index == 0:
module = __import__(module_name)
else:
module = getattr(module, module_name)
return module
pipeline = PipelineMixin.available_pipeline_by_section(pipeline_action, version, category)
try:
if single_file and pipeline.singlefile_classname != "" and pipeline.singlefile_classname is not None:
classname = pipeline.singlefile_classname
else:
classname = pipeline.classname
except KeyError:
logger.error(f"Failed to find classname for pipeline_action {pipeline_action} {version} {category}")
return
except AttributeError as e:
logger.error(f"Failed to find classname for pipeline_action {pipeline_action} {version} {category}")
return
pipeline_classname = classname.split(".")
module = None
for index, module_name in enumerate(pipeline_classname):
if index == 0:
module = __import__(module_name)
else:
module = getattr(module, module_name)
return module
35 changes: 27 additions & 8 deletions src/airunner/aihandler/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from torchvision import transforms
from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline

from PyQt6.QtCore import QSettings
from PyQt6.QtCore import pyqtSignal

from airunner.aihandler.auto_pipeline import AutoImport
from airunner.aihandler.enums import FilterType
from airunner.aihandler.enums import MessageCode
Expand All @@ -27,10 +30,16 @@
from airunner.aihandler.mixins.merge_mixin import MergeMixin
from airunner.aihandler.mixins.scheduler_mixin import SchedulerMixin
from airunner.aihandler.mixins.txttovideo_mixin import TexttovideoMixin
from airunner.aihandler.settings import LOG_LEVEL, AIRUNNER_ENVIRONMENT
from airunner.data.managers import SettingsManager
from airunner.aihandler.settings import AIRUNNER_ENVIRONMENT
from airunner.scripts.realesrgan.main import RealESRGAN
from airunner.aihandler.logger import Logger
from airunner.windows.main.settings_mixin import SettingsMixin
from airunner.windows.main.layer_mixin import LayerMixin
from airunner.windows.main.lora_mixin import LoraMixin as LoraDataMixin
from airunner.windows.main.embedding_mixin import EmbeddingMixin as EmbeddingDataMixin
from airunner.windows.main.pipeline_mixin import PipelineMixin
from airunner.windows.main.controlnet_model_mixin import ControlnetModelMixin
from airunner.windows.main.ai_model_mixin import AIModelMixin

logger = Logger(prefix="SDRunner")

Expand All @@ -44,8 +53,18 @@ class SDRunner(
EmbeddingMixin,
TexttovideoMixin,
CompelMixin,
SchedulerMixin
SchedulerMixin,

# Data Mixins
SettingsMixin,
LayerMixin,
LoraDataMixin,
EmbeddingDataMixin,
PipelineMixin,
ControlnetModelMixin,
AIModelMixin,
):
application_settings_changed_signal = pyqtSignal()
_current_model: str = ""
_previous_model: str = ""
_initialized: bool = False
Expand Down Expand Up @@ -109,7 +128,7 @@ def controlnet_model(self):
name = self.controlnet_type
if self.is_vid2vid:
name = "openpose"
model = self.settings_manager.controlnet_model_by_name(name)
model = self.controlnet_model_by_name(name)
if not model:
raise ValueError(f"Unable to find controlnet model {name}")
return model.path
Expand Down Expand Up @@ -696,10 +715,10 @@ def original_model_data(self):
def __init__(self, **kwargs):
#logger.set_level(LOG_LEVEL)
logger.info("Loading Stable Diffusion model runner...")
self.settings_manager = SettingsManager()
self.safety_checker_model = self.settings_manager.models_by_pipeline_action("safety_checker")
self.text_encoder_model = self.settings_manager.models_by_pipeline_action("text_encoder")
self.inpaint_vae_model = self.settings_manager.models_by_pipeline_action("inpaint_vae")
self.application_settings = QSettings("Capsize Games", "AI Runner")
self.safety_checker_model = self.models_by_pipeline_action("safety_checker")
self.text_encoder_model = self.models_by_pipeline_action("text_encoder")
self.inpaint_vae_model = self.models_by_pipeline_action("inpaint_vae")

self.engine = kwargs.pop("engine", None)
self.app = kwargs.get("app", None)
Expand Down
56 changes: 28 additions & 28 deletions src/airunner/data/bootstrap/controlnet_bootstrap_data.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
controlnet_bootstrap_data = {
"canny": "lllyasviel/control_v11p_sd15_canny",
"depth_leres": "lllyasviel/control_v11f1p_sd15_depth",
"depth_leres+": "lllyasviel/control_v11f1p_sd15_depth",
"depth_midas": "lllyasviel/control_v11f1p_sd15_depth",
"depth_zoe": "lllyasviel/control_v11f1p_sd15_depth",
"mlsd": "lllyasviel/control_v11p_sd15_mlsd",
"normal_bae": "lllyasviel/control_v11p_sd15_normalbae",
"normal_midas": "lllyasviel/control_v11p_sd15_normalbae",
"scribble_hed": "lllyasviel/control_v11p_sd15_scribble",
"scribble_pidinet": "lllyasviel/control_v11p_sd15_scribble",
"segmentation": "lllyasviel/control_v11p_sd15_seg",
"lineart_coarse": "lllyasviel/control_v11p_sd15_lineart",
"lineart_realistic": "lllyasviel/control_v11p_sd15_lineart",
"lineart_anime": "lllyasviel/control_v11p_sd15s2_lineart_anime",
"openpose": "lllyasviel/control_v11p_sd15_openpose",
"openpose_face": "lllyasviel/control_v11p_sd15_openpose",
"openpose_faceonly": "lllyasviel/control_v11p_sd15_openpose",
"openpose_full": "lllyasviel/control_v11p_sd15_openpose",
"openpose_hand": "lllyasviel/control_v11p_sd15_openpose",
"softedge_hed": "lllyasviel/control_v11p_sd15_softedge",
"softedge_hedsafe": "lllyasviel/control_v11p_sd15_softedge",
"softedge_pidinet": "lllyasviel/control_v11p_sd15_softedge",
"softedge_pidsafe": "lllyasviel/control_v11p_sd15_softedge",
"pixel2pixel": "lllyasviel/control_v11e_sd15_ip2p",
"inpaint": "lllyasviel/control_v11p_sd15_inpaint",
"shuffle": "lllyasviel/control_v11e_sd15_shuffle",
}
controlnet_bootstrap_data = [
{"name": "canny", "path": "lllyasviel/control_v11p_sd15_canny"},
{"name": "depth_leres", "path": "lllyasviel/control_v11f1p_sd15_depth"},
{"name": "depth_leres+", "path": "lllyasviel/control_v11f1p_sd15_depth"},
{"name": "depth_midas", "path": "lllyasviel/control_v11f1p_sd15_depth"},
{"name": "depth_zoe", "path": "lllyasviel/control_v11f1p_sd15_depth"},
{"name": "mlsd", "path": "lllyasviel/control_v11p_sd15_mlsd"},
{"name": "normal_bae", "path": "lllyasviel/control_v11p_sd15_normalbae"},
{"name": "normal_midas", "path": "lllyasviel/control_v11p_sd15_normalbae"},
{"name": "scribble_hed", "path": "lllyasviel/control_v11p_sd15_scribble"},
{"name": "scribble_pidinet", "path": "lllyasviel/control_v11p_sd15_scribble"},
{"name": "segmentation", "path": "lllyasviel/control_v11p_sd15_seg"},
{"name": "lineart_coarse", "path": "lllyasviel/control_v11p_sd15_lineart"},
{"name": "lineart_realistic", "path": "lllyasviel/control_v11p_sd15_lineart"},
{"name": "lineart_anime", "path": "lllyasviel/control_v11p_sd15s2_lineart_anime"},
{"name": "openpose", "path": "lllyasviel/control_v11p_sd15_openpose"},
{"name": "openpose_face", "path": "lllyasviel/control_v11p_sd15_openpose"},
{"name": "openpose_faceonly", "path": "lllyasviel/control_v11p_sd15_openpose"},
{"name": "openpose_full", "path": "lllyasviel/control_v11p_sd15_openpose"},
{"name": "openpose_hand", "path": "lllyasviel/control_v11p_sd15_openpose"},
{"name": "softedge_hed", "path": "lllyasviel/control_v11p_sd15_softedge"},
{"name": "softedge_hedsafe", "path": "lllyasviel/control_v11p_sd15_softedge"},
{"name": "softedge_pidinet", "path": "lllyasviel/control_v11p_sd15_softedge"},
{"name": "softedge_pidsafe", "path": "lllyasviel/control_v11p_sd15_softedge"},
{"name": "pixel2pixel", "path": "lllyasviel/control_v11e_sd15_ip2p"},
{"name": "inpaint", "path": "lllyasviel/control_v11p_sd15_inpaint"},
{"name": "shuffle", "path": "lllyasviel/control_v11e_sd15_shuffle"},
]
133 changes: 89 additions & 44 deletions src/airunner/data/bootstrap/imagefilter_bootstrap_data.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,89 @@
imagefilter_bootstrap_data = (
("Pixel Art", "pixel_art", "PixelFilter", (
("number_of_colors", "24", "int", "2", "1024"),
("smoothing", "1", "int"),
("base_size", "256", "int", "2", "256"),
)),
("Gaussian Blur", "gaussian_blur", "GaussianBlur", (
("radius", "0.0", "float"),
)),
("Box Blur", "box_blur", "BoxBlur", (
("radius", "0.0", "float"),
)),
("Color Balance", "color_balance", "ColorBalanceFilter", (
("cyan_red", "0.0", "float"),
("magenta_green", "0.0", "float"),
("yellow_blue", "0.0", "float"),
)),
("Halftone Filter", "halftone", "HalftoneFilter", (
("sample", "1", "int"),
("scale", "1", "int"),
("color_mode", "L", "str"),
)),
("Registration Error", "registration_error", "RegistrationErrorFilter", (
("red_offset_x_amount", "3", "int"),
("red_offset_y_amount", "3", "int"),
("green_offset_x_amount", "6", "int"),
("green_offset_y_amount", "6", "int"),
("blue_offset_x_amount", "9", "int"),
("blue_offset_y_amount", "9", "int")
)),
("Unsharp Mask", "unsharp_mask", "UnsharpMask", (
("radius", "0.5", "float"),
("percent", "0.5", "float"),
("threshold", "0.5", "float"),
)),
("Saturation Filter", "saturation", "SaturationFilter", (
("factor", "1.0", "float"),
)),
("RGB Noise Filter", "rgb_noise", "RGBNoiseFilter", (
("red", "0.0", "float"),
("green", "0.0", "float"),
("blue", "0.0", "float")
)),
)
imagefilter_bootstrap_data = [
{
'display_name': 'Pixel Art',
'name': 'pixel_art',
'filter_class': 'PixelFilter',
'image_filter_values': [
{'name': 'number_of_colors', 'value': '24', 'value_type': 'int', 'min_value': '2', 'max_value': '1024'},
{'name': 'smoothing', 'value': '1', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'base_size', 'value': '256', 'value_type': 'int', 'min_value': '2', 'max_value': '256'}
]
},
{
'display_name': 'Gaussian Blur',
'name': 'gaussian_blur',
'filter_class': 'GaussianBlur',
'image_filter_values': [
{'name': 'radius', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Box Blur',
'name': 'box_blur',
'filter_class': 'BoxBlur',
'image_filter_values': [
{'name': 'radius', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Color Balance',
'name': 'color_balance',
'filter_class': 'ColorBalanceFilter',
'image_filter_values': [
{'name': 'cyan_red', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'magenta_green', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'yellow_blue', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Halftone Filter',
'name': 'halftone',
'filter_class': 'HalftoneFilter',
'image_filter_values': [
{'name': 'sample', 'value': '1', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'scale', 'value': '1', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'color_mode', 'value': 'L', 'value_type': 'str', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Registration Error',
'name': 'registration_error',
'filter_class': 'RegistrationErrorFilter',
'image_filter_values': [
{'name': 'red_offset_x_amount', 'value': '3', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'red_offset_y_amount', 'value': '3', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'green_offset_x_amount', 'value': '6', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'green_offset_y_amount', 'value': '6', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'blue_offset_x_amount', 'value': '9', 'value_type': 'int', 'min_value': None, 'max_value': None},
{'name': 'blue_offset_y_amount', 'value': '9', 'value_type': 'int', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Unsharp Mask',
'name': 'unsharp_mask',
'filter_class': 'UnsharpMask',
'image_filter_values': [
{'name': 'radius', 'value': '0.5', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'percent', 'value': '0.5', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'threshold', 'value': '0.5', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'Saturation Filter',
'name': 'saturation',
'filter_class': 'SaturationFilter',
'image_filter_values': [
{'name': 'factor', 'value': '1.0', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
},
{
'display_name': 'RGB Noise Filter',
'name': 'rgb_noise',
'filter_class': 'RGBNoiseFilter',
'image_filter_values': [
{'name': 'red', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'green', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None},
{'name': 'blue', 'value': '0.0', 'value_type': 'float', 'min_value': None, 'max_value': None}
]
}
]
Loading

0 comments on commit c43fb15

Please sign in to comment.