mirror of https://github.com/vladmandic/automatic
parent
7588ec0636
commit
295fe6fbd3
|
|
@ -40,5 +40,4 @@ async def post_rembg(
|
|||
|
||||
|
||||
def register_api(app):
|
||||
print('HERE')
|
||||
app.add_api_route("/sdapi/v1/rembg", post_rembg, methods=["POST"], tags=["REMBG"])
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ScriptPostprocessing:
|
|||
args_from = None
|
||||
args_to = None
|
||||
order = 1000 # scripts will be ordred by this value in postprocessing UI
|
||||
name = None # this function should return the title of the script
|
||||
name = 'unknown' # this function should return the title of the script
|
||||
group = None # A gr.Group component that has all script's UI inside it
|
||||
|
||||
def ui(self):
|
||||
|
|
@ -39,6 +39,9 @@ class ScriptPostprocessing:
|
|||
def image_changed(self):
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return f"ScriptPostprocessing(name={self.name} filename={self.filename})"
|
||||
|
||||
|
||||
def wrap_call(func, filename, funcname, *args, default=None, **kwargs):
|
||||
try:
|
||||
|
|
@ -60,6 +63,9 @@ class ScriptPostprocessingRunner:
|
|||
for script_class, path, _basedir, _script_module in scripts_data:
|
||||
script: ScriptPostprocessing = script_class()
|
||||
script.filename = path
|
||||
if script.name is None or script.name == "unknown":
|
||||
log.warning(f'Script: path={path} cls={script_class} invalid')
|
||||
continue
|
||||
if script.name == "Simple Upscale":
|
||||
continue
|
||||
self.scripts.append(script)
|
||||
|
|
@ -68,7 +74,9 @@ class ScriptPostprocessingRunner:
|
|||
script.args_from = len(inputs)
|
||||
script.args_to = len(inputs)
|
||||
script.controls = wrap_call(script.ui, script.filename, "ui")
|
||||
for control in script.controls.values() if script.controls is not None else []:
|
||||
if script.controls is None:
|
||||
script.controls = {}
|
||||
for control in script.controls.values():
|
||||
control.custom_script_source = os.path.basename(script.filename)
|
||||
inputs += list(script.controls.values())
|
||||
script.args_to = len(inputs)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
import gradio as gr
|
||||
from PIL import Image
|
||||
from modules.scripts_postprocessing import ScriptPostprocessing, PostprocessedImage
|
||||
from modules import scripts_postprocessing
|
||||
|
||||
|
||||
models = [
|
||||
|
|
@ -18,7 +18,7 @@ models = [
|
|||
]
|
||||
|
||||
|
||||
class ScriptPostprocessingUpscale(ScriptPostprocessing):
|
||||
class ScriptPostprocessingRembg(scripts_postprocessing.ScriptPostprocessing):
|
||||
name = "Remove background"
|
||||
order = 20000
|
||||
model = None
|
||||
|
|
@ -59,7 +59,7 @@ class ScriptPostprocessingUpscale(ScriptPostprocessing):
|
|||
"alpha_matting_erode_size": alpha_matting_erode_size,
|
||||
}
|
||||
|
||||
def process(self, pp: PostprocessedImage, model, merge_alpha, refine, mask_only, postprocess_mask, alpha_matting, alpha_matting_foreground_threshold, alpha_matting_background_threshold, alpha_matting_erode_size): # pylint: disable=arguments-differ
|
||||
def process(self, pp: scripts_postprocessing.PostprocessedImage, model, merge_alpha, refine, mask_only, postprocess_mask, alpha_matting, alpha_matting_foreground_threshold, alpha_matting_background_threshold, alpha_matting_erode_size): # pylint: disable=arguments-differ
|
||||
from modules.logger import log
|
||||
if not model or model == "none":
|
||||
return pp
|
||||
|
|
@ -108,7 +108,7 @@ class ScriptPostprocessingUpscale(ScriptPostprocessing):
|
|||
image = flattened
|
||||
|
||||
if isinstance(pp, Image.Image):
|
||||
pp = PostprocessedImage(image=image, info={ **info, 'Rembg': model })
|
||||
pp = scripts_postprocessing.PostprocessedImage(image=image, info={**info, "Rembg": model})
|
||||
else:
|
||||
pp.image = image
|
||||
pp.info['Rembg'] = model
|
||||
|
|
|
|||
Loading…
Reference in New Issue