mirror of
https://git.mirrors.martin98.com/https://github.com/danielgatis/rembg
synced 2025-08-15 11:15:55 +08:00
add the dead pill stop.txt
This commit is contained in:
parent
b601763e07
commit
d63da2e6fb
@ -22,6 +22,10 @@ from .session_factory import new_session
|
|||||||
from .sessions import sessions_class
|
from .sessions import sessions_class
|
||||||
from .sessions.base import BaseSession
|
from .sessions.base import BaseSession
|
||||||
|
|
||||||
|
import onnxruntime as ort
|
||||||
|
|
||||||
|
ort.set_default_logger_severity(3)
|
||||||
|
|
||||||
kernel = getStructuringElement(MORPH_ELLIPSE, (3, 3))
|
kernel = getStructuringElement(MORPH_ELLIPSE, (3, 3))
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +80,14 @@ from ..sessions import sessions_names
|
|||||||
show_default=True,
|
show_default=True,
|
||||||
help="watches a folder for changes",
|
help="watches a folder for changes",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"-d",
|
||||||
|
"--delete_input",
|
||||||
|
default=False,
|
||||||
|
is_flag=True,
|
||||||
|
show_default=True,
|
||||||
|
help="delete input file after processing",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-bgc",
|
"-bgc",
|
||||||
"--bgcolor",
|
"--bgcolor",
|
||||||
@ -115,6 +123,7 @@ def p_command(
|
|||||||
input: pathlib.Path,
|
input: pathlib.Path,
|
||||||
output: pathlib.Path,
|
output: pathlib.Path,
|
||||||
watch: bool,
|
watch: bool,
|
||||||
|
delete_input: bool,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
@ -132,6 +141,7 @@ def p_command(
|
|||||||
input (pathlib.Path): The path to the input folder.
|
input (pathlib.Path): The path to the input folder.
|
||||||
output (pathlib.Path): The path to the output folder.
|
output (pathlib.Path): The path to the output folder.
|
||||||
watch (bool): Whether to watch the input folder for changes.
|
watch (bool): Whether to watch the input folder for changes.
|
||||||
|
delete_input (bool): Whether to delete the input file after processing.
|
||||||
**kwargs: Additional keyword arguments.
|
**kwargs: Additional keyword arguments.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -167,6 +177,10 @@ def p_command(
|
|||||||
print(
|
print(
|
||||||
f"processed: {each_input.absolute()} -> {each_output.absolute()}"
|
f"processed: {each_input.absolute()} -> {each_output.absolute()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if delete_input:
|
||||||
|
each_input.unlink()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@ -179,13 +193,23 @@ def p_command(
|
|||||||
process(each_input)
|
process(each_input)
|
||||||
|
|
||||||
if watch:
|
if watch:
|
||||||
|
should_watch = True
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
|
|
||||||
class EventHandler(FileSystemEventHandler):
|
class EventHandler(FileSystemEventHandler):
|
||||||
def on_any_event(self, event: FileSystemEvent) -> None:
|
def on_any_event(self, event: FileSystemEvent) -> None:
|
||||||
if not (
|
if (
|
||||||
|
not (
|
||||||
event.is_directory or event.event_type in ["deleted", "closed"]
|
event.is_directory or event.event_type in ["deleted", "closed"]
|
||||||
|
)
|
||||||
|
and pathlib.Path(event.src_path).exists()
|
||||||
):
|
):
|
||||||
|
if event.src_path.endswith("stop.txt"):
|
||||||
|
nonlocal should_watch
|
||||||
|
should_watch = False
|
||||||
|
pathlib.Path(event.src_path).unlink()
|
||||||
|
return
|
||||||
|
|
||||||
process(pathlib.Path(event.src_path))
|
process(pathlib.Path(event.src_path))
|
||||||
|
|
||||||
event_handler = EventHandler()
|
event_handler = EventHandler()
|
||||||
@ -193,7 +217,7 @@ def p_command(
|
|||||||
observer.start()
|
observer.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while should_watch:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user