Spaces:
Sleeping
Sleeping
import subprocess | |
import sys | |
from typing import Any, Callable | |
from style_bert_vits2.logging import logger | |
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT | |
def run_script_with_log( | |
cmd: list[str], ignore_warning: bool = False | |
) -> tuple[bool, str]: | |
""" | |
ๆๅฎใใใใณใใณใใๅฎ่กใใใใฎใญใฐใ่จ้ฒใใใ | |
Args: | |
cmd: ๅฎ่กใใใณใใณใใฎใชในใ | |
ignore_warning: ่ญฆๅใ็ก่ฆใใใใฉใใใฎใใฉใฐ | |
Returns: | |
tuple[bool, str]: ๅฎ่กใๆๅใใใใฉใใใฎใใผใซๅคใจใใจใฉใผใพใใฏ่ญฆๅใฎใกใใปใผใธ๏ผใใๅ ดๅ๏ผ | |
""" | |
logger.info(f"Running: {' '.join(cmd)}") | |
result = subprocess.run( | |
[sys.executable] + cmd, | |
stdout=SAFE_STDOUT, | |
stderr=subprocess.PIPE, | |
text=True, | |
encoding="utf-8", | |
check=False, | |
) | |
if result.returncode != 0: | |
logger.error(f"Error: {' '.join(cmd)}\n{result.stderr}") | |
return False, result.stderr | |
elif result.stderr and not ignore_warning: | |
logger.warning(f"Warning: {' '.join(cmd)}\n{result.stderr}") | |
return True, result.stderr | |
logger.success(f"Success: {' '.join(cmd)}") | |
return True, "" | |
def second_elem_of( | |
original_function: Callable[..., tuple[Any, Any]] | |
) -> Callable[..., Any]: | |
""" | |
ไธใใใใ้ขๆฐใใฉใใใใใใฎๆปใๅคใฎ 2 ็ช็ฎใฎ่ฆ็ด ใฎใฟใ่ฟใ้ขๆฐใ็ๆใใใ | |
Args: | |
original_function (Callable[..., tuple[Any, Any]])): ใฉใใใใๅ ใฎ้ขๆฐ | |
Returns: | |
Callable[..., Any]: ๅ ใฎ้ขๆฐใฎๆปใๅคใฎ 2 ็ช็ฎใฎ่ฆ็ด ใฎใฟใ่ฟใ้ขๆฐ | |
""" | |
def inner_function(*args, **kwargs) -> Any: # type: ignore | |
return original_function(*args, **kwargs)[1] | |
return inner_function | |