-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
150 additions
and
980 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter" | ||
}, | ||
"python.formatting.provider": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +0,0 @@ | ||
from ..config import config | ||
|
||
if config.novelai_mode == "novelai": | ||
from .novelai import Draw | ||
elif config.novelai_mode == "naifu": | ||
from .naifu import Draw | ||
elif config.novelai_mode == "sd": | ||
from .sd import Draw | ||
else: | ||
raise RuntimeError(f"错误的mode设置,支持的字符串为'novelai','naifu','sd'") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from ..core.pipeline import ParallelPipeline, SelectivePipeline | ||
|
||
|
||
class BackendBase(ParallelPipeline, SelectivePipeline): | ||
... |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import heapq | ||
from typing import Callable, Type | ||
|
||
|
||
class Processor: | ||
"""加工器""" | ||
|
||
def run(self): | ||
... | ||
|
||
|
||
class PipelineMeta(type): | ||
def __new__(cls, name, bases, attrs): | ||
if "run" not in attrs: | ||
# 检查是否存在父类,并按继承顺序调用各个父类的run方法 | ||
def run(self): | ||
for base in bases: | ||
if hasattr(base, "run"): | ||
getattr(base, "run")(self) | ||
|
||
attrs["run"] = run | ||
return super().__new__(cls, name, bases, attrs) | ||
|
||
|
||
class Pipeline(Processor, metaclass=PipelineMeta): | ||
""" | ||
流水线基类,不包含处理加工器的流程,除非要自己实现,否则应继承子类 | ||
流水线本身也是一个加工器,只是流水线的工作方式不同 | ||
""" | ||
|
||
Pipelines = [] | ||
|
||
def _register(self, Pipeline, priority, block): | ||
heapq.heappush(self.Pipelines, (priority, block, Pipeline)) | ||
|
||
async def preprocess(self): | ||
"""预处理""" | ||
... | ||
|
||
async def on_preprocess(self, func): | ||
... | ||
|
||
async def postprocess(self): | ||
... | ||
|
||
async def on_postprocess(self, func): | ||
... | ||
|
||
def handle( | ||
self, priority: int, block: bool | ||
) -> Callable[[Callable | Type["Processor"]], Type["Processor"]]: | ||
"""通过该函数将函数注册为加工器""" | ||
|
||
def wrapper(subPipeline: Callable | Type["Processor"]) -> Type["Processor"]: | ||
if isinstance(subPipeline, Callable): | ||
sub = type(subPipeline.__name__, (Processor,), {}) # TODO | ||
return sub | ||
else: | ||
self._register(subPipeline, priority, block) | ||
return subPipeline | ||
|
||
return wrapper | ||
|
||
|
||
class LinearPipeline(Pipeline): | ||
... | ||
|
||
|
||
class ParallelPipeline(Pipeline): | ||
... | ||
|
||
|
||
class SelectivePipeline(Pipeline): | ||
... | ||
|
||
|
||
class Context: | ||
"""事件,只保存数据在各个Pipeline之间传递""" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from ..config import config | ||
|
||
if config.novelai_mode == "novelai": | ||
from .novelai import Draw | ||
elif config.novelai_mode == "naifu": | ||
from .naifu import Draw | ||
elif config.novelai_mode == "sd": | ||
from .sd import Draw | ||
else: | ||
raise RuntimeError(f"错误的mode设置,支持的字符串为'novelai','naifu','sd'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.