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 |
+
import ast
|
| 8 |
+
|
| 9 |
+
abs_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
+
git = os.path.join(abs_path, "s", "git", "cmd", "git.exe")
|
| 11 |
+
master_path = os.path.join(abs_path, "p")
|
| 12 |
+
python = os.path.join(abs_path, "s", "python", "python.exe")
|
| 13 |
+
parser = argparse.ArgumentParser()
|
| 14 |
+
|
| 15 |
+
parser.add_argument('-wf', '--webcam-false', action='store_true')
|
| 16 |
+
parser.add_argument('-wt', '--webcam-true', action='store_true')
|
| 17 |
+
parser.add_argument('-mb', '--master-branch', action='store_true')
|
| 18 |
+
parser.add_argument('-nb', '--next-branch', action='store_true')
|
| 19 |
+
parser.add_argument('-nu', '--no-update', action='store_true')
|
| 20 |
+
|
| 21 |
+
args = parser.parse_args()
|
| 22 |
+
|
| 23 |
+
def run_git_command(args):
|
| 24 |
+
subprocess.run([git] + args, check=True)
|
| 25 |
+
|
| 26 |
+
def uncensore(branch):
|
| 27 |
+
functions_to_modify = {
|
| 28 |
+
"analyse_frame": False,
|
| 29 |
+
"analyse_stream": False,
|
| 30 |
+
"forward": 0.0,
|
| 31 |
+
"prepare_frame": "frame",
|
| 32 |
+
"analyse_video": False,
|
| 33 |
+
"analyse_image": False
|
| 34 |
+
}
|
| 35 |
+
file_path = os.path.join(master_path, branch, 'facefusion', 'content_analyser.py')
|
| 36 |
+
|
| 37 |
+
if not os.path.exists(file_path):
|
| 38 |
+
print(f"Файл {file_path} не найден.")
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 42 |
+
source_code = file.read()
|
| 43 |
+
|
| 44 |
+
tree = ast.parse(source_code)
|
| 45 |
+
|
| 46 |
+
class ModifyFunctions(ast.NodeTransformer):
|
| 47 |
+
def visit_FunctionDef(self, node):
|
| 48 |
+
if node.name in functions_to_modify:
|
| 49 |
+
return_value = functions_to_modify[node.name]
|
| 50 |
+
if isinstance(return_value, bool):
|
| 51 |
+
node.body = [ast.Return(value=ast.Constant(value=return_value))]
|
| 52 |
+
elif isinstance(return_value, float):
|
| 53 |
+
node.body = [ast.Return(value=ast.Constant(value=return_value))]
|
| 54 |
+
elif isinstance(return_value, str) and return_value == "frame":
|
| 55 |
+
node.body = [ast.Return(value=ast.Name(id='vision_frame', ctx=ast.Load()))]
|
| 56 |
+
|
| 57 |
+
return node
|
| 58 |
+
|
| 59 |
+
modified_tree = ModifyFunctions().visit(tree)
|
| 60 |
+
modified_code = ast.unparse(modified_tree)
|
| 61 |
+
|
| 62 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
| 63 |
+
file.write(modified_code)
|
| 64 |
+
|
| 65 |
+
def prepare_environment(branch):
|
| 66 |
+
branch_path = os.path.join(master_path, branch)
|
| 67 |
+
os.chdir(branch_path)
|
| 68 |
+
if not args.no_update:
|
| 69 |
+
run_git_command(['reset', '--hard'])
|
| 70 |
+
run_git_command(['checkout', branch])
|
| 71 |
+
run_git_command(['pull', 'origin', branch, '--rebase'])
|
| 72 |
+
uncensore(branch)
|
| 73 |
+
|
| 74 |
+
def ask_webcam_mode(language):
|
| 75 |
+
webcam_choice = input(get_localized_text(language, "enable_webcam")).strip().lower()
|
| 76 |
+
if webcam_choice in ["y", "д"]:
|
| 77 |
+
return True
|
| 78 |
+
elif webcam_choice in ["n", "н"]:
|
| 79 |
+
return False
|
| 80 |
+
return None
|
| 81 |
+
|
| 82 |
+
def start_ff(branch, webcam_mode=False):
|
| 83 |
+
path_to_branch = os.path.join(master_path, branch)
|
| 84 |
+
second_file = os.path.join(path_to_branch, "facefusion.py")
|
| 85 |
+
args = ["run", "--open-browser", "--ui-layouts", "webcam"] if webcam_mode else ["run", "--open-browser"]
|
| 86 |
+
cmd = f'"{python}" "{second_file}" {" ".join(args)}'
|
| 87 |
+
subprocess.run(cmd, shell=True, check=True)
|
| 88 |
+
|
| 89 |
+
def get_localized_text(language, key):
|
| 90 |
+
texts = {
|
| 91 |
+
"en": {
|
| 92 |
+
"choose_action": "Choose an action:",
|
| 93 |
+
"update_master": "1. Update to the master branch and start it",
|
| 94 |
+
"update_next": "2. Update to the next branch and start it",
|
| 95 |
+
"enter_choice": "Enter the number of the action: ",
|
| 96 |
+
"invalid_choice": "Invalid choice, please try again.",
|
| 97 |
+
"enable_webcam": "Enable webcam mode? (Y/N): ",
|
| 98 |
+
},
|
| 99 |
+
"ru": {
|
| 100 |
+
"choose_action": "Выберите действие:",
|
| 101 |
+
"update_master": "1. Обновить до обычной ветки и запустить ее (master)",
|
| 102 |
+
"update_next": "2. Обновить до бета ветки и запустить ее (next)",
|
| 103 |
+
"enter_choice": "Введите номер действия: ",
|
| 104 |
+
"invalid_choice": "Неверный выбор, попробуйте снова.",
|
| 105 |
+
"enable_webcam": "Включить режим вебкамеры? (Y/N): ",
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
return texts[language].get(key, "")
|
| 109 |
+
|
| 110 |
+
def get_system_language():
|
| 111 |
+
try:
|
| 112 |
+
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Control Panel\International")
|
| 113 |
+
language = winreg.QueryValueEx(key, "LocaleName")[0]
|
| 114 |
+
winreg.CloseKey(key)
|
| 115 |
+
return "ru" if language.split('-')[0].lower() == "ru" else "en"
|
| 116 |
+
except WindowsError:
|
| 117 |
+
return "ru" if locale.getlocale()[0].split('_')[0].lower() == "ru" else "en"
|
| 118 |
+
|
| 119 |
+
def facefusion():
|
| 120 |
+
language = get_system_language()
|
| 121 |
+
if args.master_branch or args.next_branch:
|
| 122 |
+
branch = "master" if args.master_branch else "next"
|
| 123 |
+
prepare_environment(branch)
|
| 124 |
+
webcam_mode = True if args.webcam_true else False if args.webcam_false else ask_webcam_mode(language)
|
| 125 |
+
start_ff(branch, webcam_mode)
|
| 126 |
+
return
|
| 127 |
+
|
| 128 |
+
while True:
|
| 129 |
+
print(get_localized_text(language, "choose_action"))
|
| 130 |
+
print(get_localized_text(language, "update_master"))
|
| 131 |
+
print(get_localized_text(language, "update_next"))
|
| 132 |
+
choice = input(get_localized_text(language, "enter_choice")).strip()
|
| 133 |
+
if choice in ['1', '2']:
|
| 134 |
+
branch = "master" if choice == '1' else "next"
|
| 135 |
+
prepare_environment(branch)
|
| 136 |
+
webcam_mode = ask_webcam_mode(language)
|
| 137 |
+
start_ff(branch, webcam_mode)
|
| 138 |
+
break
|
| 139 |
+
else:
|
| 140 |
+
print(get_localized_text(language, "invalid_choice"))
|
| 141 |
+
|
| 142 |
+
if __name__ == "__main__":
|
| 143 |
+
facefusion()
|