facetest / facefusion /common_helper.py
LULDev's picture
Upload folder using huggingface_hub
a1da63c verified
import platform
from typing import Any, Sequence
def is_linux() -> bool:
return platform.system().lower() == 'linux'
def is_macos() -> bool:
return platform.system().lower() == 'darwin'
def is_windows() -> bool:
return platform.system().lower() == 'windows'
def create_int_metavar(int_range : Sequence[int]) -> str:
return '[' + str(int_range[0]) + '..' + str(int_range[-1]) + ':' + str(calc_int_step(int_range)) + ']'
def create_float_metavar(float_range : Sequence[float]) -> str:
return '[' + str(float_range[0]) + '..' + str(float_range[-1]) + ':' + str(calc_float_step(float_range)) + ']'
def create_int_range(start : int, end : int, step : int) -> Sequence[int]:
int_range = []
current = start
while current <= end:
int_range.append(current)
current += step
return int_range
def create_float_range(start : float, end : float, step : float) -> Sequence[float]:
float_range = []
current = start
while current <= end:
float_range.append(round(current, 2))
current = round(current + step, 2)
return float_range
def calc_int_step(int_range : Sequence[int]) -> int:
return int_range[1] - int_range[0]
def calc_float_step(float_range : Sequence[float]) -> float:
return round(float_range[1] - float_range[0], 2)
def map_float(value : float, start : float, end : float, map_start : float, map_end : float) -> float:
ratio = (value - start) / (end - start)
map_value = map_start + (map_end - map_start) * ratio
return map_value
def get_first(__list__ : Any) -> Any:
return next(iter(__list__), None)
def get_last(__list__ : Any) -> Any:
return next(reversed(__list__), None)