| import os | |
| import subprocess | |
| import locale | |
| import winreg | |
| import argparse | |
| abs_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| git = os.path.join(abs_path, "s", "git", "cmd", "git.exe") | |
| master_path = os.path.join(abs_path, "p") | |
| python = os.path.join(abs_path, "s", "python", "python.exe") | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('-wf', '--webcam-false', action='store_true') | |
| parser.add_argument('-wt', '--webcam-true', action='store_true') | |
| parser.add_argument('-mb', '--master-branch', action='store_true') | |
| parser.add_argument('-nb', '--next-branch', action='store_true') | |
| parser.add_argument('-nu', '--no-update', action='store_true') | |
| args = parser.parse_args() | |
| def run_git_command(args): | |
| subprocess.run([git] + args, check=True) | |
| def prepare_environment(branch): | |
| branch_path = os.path.join(master_path, branch) | |
| os.chdir(branch_path) | |
| if not args.no_update: | |
| run_git_command(['reset', '--hard']) | |
| run_git_command(['checkout', branch]) | |
| run_git_command(['pull', 'origin', branch, '--rebase']) | |
| def ask_webcam_mode(language): | |
| """Спрашивает у пользователя режим вебкамеры и возвращает определенный результат""" | |
| webcam_choice = input(get_localized_text(language, "enable_webcam")).strip().lower() | |
| if webcam_choice in ["y", "д"]: | |
| return True | |
| elif webcam_choice in ["n", "н"]: | |
| return False | |
| else: | |
| print("Неверный ввод, вебкамера отключена по умолчанию.") | |
| return False | |
| def start_ff(branch, webcam_mode=False): | |
| path_to_branch = os.path.join(master_path, branch) | |
| second_file = os.path.join(path_to_branch, "facefusion.py") | |
| args = ["run", "--open-browser", "--ui-layouts", "webcam"] if webcam_mode else ["run", "--open-browser"] | |
| cmd = f'"{python}" "{second_file}" {" ".join(args)}' | |
| subprocess.run(cmd, shell=True, check=True) | |
| def get_localized_text(language, key): | |
| texts = { | |
| "en": { | |
| "choose_action": "Choose an action:", | |
| "update_master": "1. Update to the master branch and start it", | |
| "update_next": "2. Update to the next branch and start it", | |
| "enter_choice": "Enter the number of the action: ", | |
| "invalid_choice": "Invalid choice, please try again.", | |
| "enable_webcam": "Enable webcam mode? (Y/N): ", | |
| }, | |
| "ru": { | |
| "choose_action": "Выберите действие:", | |
| "update_master": "1. Обновить до обычной ветки и запустить ее (master)", | |
| "update_next": "2. Обновить до бета ветки и запустить ее (next)", | |
| "enter_choice": "Введите номер действия: ", | |
| "invalid_choice": "Неверный выбор, попробуйте снова.", | |
| "enable_webcam": "Включить режим вебкамеры? (Y/N): ", | |
| } | |
| } | |
| return texts[language].get(key, "") | |
| def get_system_language(): | |
| """Определяет системный язык с корректной обработкой None значений""" | |
| try: | |
| key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Control Panel\International") | |
| language = winreg.QueryValueEx(key, "LocaleName")[0] | |
| winreg.CloseKey(key) | |
| if language: | |
| return "ru" if language.split('-')[0].lower() == "ru" else "en" | |
| except (WindowsError, AttributeError): | |
| pass | |
| try: | |
| locale_info = locale.getlocale()[0] | |
| if locale_info: | |
| return "ru" if locale_info.split('_')[0].lower() == "ru" else "en" | |
| except (AttributeError, IndexError): | |
| pass | |
| return "ru" | |
| def facefusion(): | |
| language = get_system_language() | |
| if args.master_branch or args.next_branch: | |
| branch = "master" if args.master_branch else "next" | |
| prepare_environment(branch) | |
| if args.webcam_true: | |
| webcam_mode = True | |
| elif args.webcam_false: | |
| webcam_mode = False | |
| else: | |
| webcam_mode = ask_webcam_mode(language) | |
| start_ff(branch, webcam_mode) | |
| return | |
| while True: | |
| print(get_localized_text(language, "choose_action")) | |
| print(get_localized_text(language, "update_master")) | |
| print(get_localized_text(language, "update_next")) | |
| choice = input(get_localized_text(language, "enter_choice")).strip() | |
| if choice in ['1', '2']: | |
| branch = "master" if choice == '1' else "next" | |
| prepare_environment(branch) | |
| webcam_mode = ask_webcam_mode(language) | |
| start_ff(branch, webcam_mode) | |
| break | |
| else: | |
| print(get_localized_text(language, "invalid_choice")) | |
| if __name__ == "__main__": | |
| facefusion() |