mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-04-30 03:01:18 +00:00
feat: rich print, traceback
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import Optional, Union
|
|||||||
|
|
||||||
from huggingface_hub import hf_hub_download
|
from huggingface_hub import hf_hub_download
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
from rich import print
|
||||||
|
|
||||||
repo_id = "Bingsu/adetailer"
|
repo_id = "Bingsu/adetailer"
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ def hf_download(file: str):
|
|||||||
try:
|
try:
|
||||||
path = hf_hub_download(repo_id, file)
|
path = hf_hub_download(repo_id, file)
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = f"[-] ADetailer: Failed to load model {file!r}"
|
msg = f"[-] ADetailer: Failed to load model {file!r} from huggingface"
|
||||||
print(msg)
|
print(msg)
|
||||||
path = "INVALID"
|
path = "INVALID"
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ def mediapipe_predict(
|
|||||||
if model_type in mapping:
|
if model_type in mapping:
|
||||||
func = mapping[model_type]
|
func = mapping[model_type]
|
||||||
return func(image, confidence)
|
return func(image, confidence)
|
||||||
msg = f"[-] ADetailer: Invalid mediapipe model type: {model_type}"
|
msg = f"[-] ADetailer: Invalid mediapipe model type: {model_type}, Available: {list(mapping.keys())!r}"
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from contextlib import contextmanager, suppress
|
from contextlib import contextmanager
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -14,6 +15,8 @@ from typing import Any
|
|||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import torch
|
import torch
|
||||||
|
from rich import print
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
import modules
|
import modules
|
||||||
from adetailer import (
|
from adetailer import (
|
||||||
@@ -42,10 +45,6 @@ from sd_webui.processing import (
|
|||||||
)
|
)
|
||||||
from sd_webui.shared import cmd_opts, opts, state
|
from sd_webui.shared import cmd_opts, opts, state
|
||||||
|
|
||||||
with suppress(ImportError):
|
|
||||||
from rich import print
|
|
||||||
|
|
||||||
|
|
||||||
no_huggingface = getattr(cmd_opts, "ad_no_huggingface", False)
|
no_huggingface = getattr(cmd_opts, "ad_no_huggingface", False)
|
||||||
adetailer_dir = Path(models_path, "adetailer")
|
adetailer_dir = Path(models_path, "adetailer")
|
||||||
model_mapping = get_models(adetailer_dir, huggingface=not no_huggingface)
|
model_mapping = get_models(adetailer_dir, huggingface=not no_huggingface)
|
||||||
@@ -84,6 +83,18 @@ def pause_total_tqdm():
|
|||||||
opts.data["multiple_tqdm"] = orig
|
opts.data["multiple_tqdm"] = orig
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def rich_traceback():
|
||||||
|
string = io.StringIO()
|
||||||
|
console = Console(file=string, force_terminal=True)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except Exception as e:
|
||||||
|
console.print_exception(show_locals=True)
|
||||||
|
output = "\n" + string.getvalue()
|
||||||
|
raise RuntimeError(output) from e
|
||||||
|
|
||||||
|
|
||||||
class AfterDetailerScript(scripts.Script):
|
class AfterDetailerScript(scripts.Script):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -519,6 +530,9 @@ class AfterDetailerScript(scripts.Script):
|
|||||||
if is_mediapipe:
|
if is_mediapipe:
|
||||||
print(f"mediapipe: {steps} detected.")
|
print(f"mediapipe: {steps} detected.")
|
||||||
|
|
||||||
|
_user_pt = p.prompt
|
||||||
|
_user_ng = p.negative_prompt
|
||||||
|
|
||||||
p2 = copy(i2i)
|
p2 = copy(i2i)
|
||||||
for j in range(steps):
|
for j in range(steps):
|
||||||
p2.image_mask = masks[j]
|
p2.image_mask = masks[j]
|
||||||
@@ -541,6 +555,7 @@ class AfterDetailerScript(scripts.Script):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@rich_traceback()
|
||||||
def postprocess_image(self, p, pp, *args_):
|
def postprocess_image(self, p, pp, *args_):
|
||||||
if getattr(p, "_disable_adetailer", False):
|
if getattr(p, "_disable_adetailer", False):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ from typing import TYPE_CHECKING
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
def on_app_started(callback: Callable):
|
||||||
|
pass
|
||||||
|
|
||||||
def on_ui_settings(callback: Callable):
|
def on_ui_settings(callback: Callable):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@ if TYPE_CHECKING:
|
|||||||
else:
|
else:
|
||||||
from modules.script_callbacks import (
|
from modules.script_callbacks import (
|
||||||
on_after_component,
|
on_after_component,
|
||||||
|
on_app_started,
|
||||||
on_before_ui,
|
on_before_ui,
|
||||||
on_ui_settings,
|
on_ui_settings,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user