
* Replace audio whenever set via source * use scale_face_landmark_5() in age_modifier * Fix wording and ordering of options * Adjust wording for face editor * Fix wording for processors * Switch order of frame colorizer options * That condition is actual not needed * Simplify UI layout API by removing pre_render() * Clean args and safe cast ini values (#775) * Clean args and safe cast ini values * Clean args and safe cast ini values * Clean args and safe cast ini values * Introduce paths group * Fix job list command and change order * Add job list testing todo * Fix spacing in typing * Fix benchmark by ignoring audio * Simplify and avoid knowing the provider values (#782) * Fix logger table with empty value * Complete Typing --------- Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>
93 lines
2.2 KiB
Python
93 lines
2.2 KiB
Python
from configparser import ConfigParser
|
|
from typing import Any, List, Optional
|
|
|
|
from facefusion import state_manager
|
|
from facefusion.common_helper import cast_float, cast_int
|
|
|
|
CONFIG = None
|
|
|
|
|
|
def get_config() -> ConfigParser:
|
|
global CONFIG
|
|
|
|
if CONFIG is None:
|
|
CONFIG = ConfigParser()
|
|
CONFIG.read(state_manager.get_item('config_path'), encoding = 'utf-8')
|
|
return CONFIG
|
|
|
|
|
|
def clear_config() -> None:
|
|
global CONFIG
|
|
|
|
CONFIG = None
|
|
|
|
|
|
def get_str_value(key : str, fallback : Optional[str] = None) -> Optional[str]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return str(value or fallback)
|
|
return None
|
|
|
|
|
|
def get_int_value(key : str, fallback : Optional[str] = None) -> Optional[int]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return cast_int(value or fallback)
|
|
return None
|
|
|
|
|
|
def get_float_value(key : str, fallback : Optional[str] = None) -> Optional[float]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return cast_float(value or fallback)
|
|
return None
|
|
|
|
|
|
def get_bool_value(key : str, fallback : Optional[str] = None) -> Optional[bool]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value == 'True' or fallback == 'True':
|
|
return True
|
|
if value == 'False' or fallback == 'False':
|
|
return False
|
|
return None
|
|
|
|
|
|
def get_str_list(key : str, fallback : Optional[str] = None) -> Optional[List[str]]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return [ str(value) for value in (value or fallback).split(' ') ]
|
|
return None
|
|
|
|
|
|
def get_int_list(key : str, fallback : Optional[str] = None) -> Optional[List[int]]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return [ cast_int(value) for value in (value or fallback).split(' ') ]
|
|
return None
|
|
|
|
|
|
def get_float_list(key : str, fallback : Optional[str] = None) -> Optional[List[float]]:
|
|
value = get_value_by_notation(key)
|
|
|
|
if value or fallback:
|
|
return [ cast_float(value) for value in (value or fallback).split(' ') ]
|
|
return None
|
|
|
|
|
|
def get_value_by_notation(key : str) -> Optional[Any]:
|
|
config = get_config()
|
|
|
|
if '.' in key:
|
|
section, name = key.split('.')
|
|
if section in config and name in config[section]:
|
|
return config[section][name]
|
|
if key in config:
|
|
return config[key]
|
|
return None
|