File size: 5,940 Bytes
d94c15e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import os
import subprocess
import sys
import locale
import winreg
def get_available_drives():
drives = []
for drive in range(65, 91): # ASCII коды от A (65) до Z (90)
drive_letter = f"{chr(drive)}:\\"
if os.path.exists(drive_letter):
drives.append(drive_letter)
return drives
def get_path_for_install():
language = get_system_language()
if not language:
language = input(get_localized_text("en", "choose_language")).strip().lower()
if language not in ["en", "ru"]:
language = "en"
default_path = "C:\\"
user_input = input(get_localized_text(language, "which_path") + f" ({default_path}): ").strip()
install_path = user_input if user_input else default_path
full_path = os.path.join(install_path, 'portablesource')
if not os.path.exists(full_path):
try:
os.makedirs(full_path)
except OSError:
print(get_localized_text(language, "error_creating_directory"))
return get_path_for_install()
with open(os.path.join(full_path, 'installed.txt'), 'w') as f:
f.write('installed')
return full_path
def get_install_path():
drives = get_available_drives()
install_path = None
for drive in drives:
possible_path = os.path.join(drive, 'portablesource', 'installed.txt')
if os.path.exists(possible_path):
install_path = os.path.dirname(possible_path)
return install_path
else:
install_path = get_path_for_install()
return install_path
return install_path
abs_path = get_install_path()
git = os.path.join(abs_path, "system", "git", "cmd", "git.exe")
ff_obs = os.path.join(abs_path, "sources", "facefusion")
master_path = os.path.join(ff_obs, "master")
python = os.path.join(abs_path, "system", "python", "python.exe")
master = os.path.join(ff_obs, "master", "facefusion", "content_analyser.py")
venv_path = venv_path = os.path.join(ff_obs, "venv")
activate_script = os.path.join(venv_path, "Scripts", "activate.bat")
def get_uv_path():
if sys.platform.startswith('win'):
scripts_dir = os.path.join(os.path.dirname(python), 'Scripts')
uv_executable = os.path.join(scripts_dir, "uv.exe")
else:
scripts_dir = os.path.join(os.path.dirname(os.path.dirname(python)), 'bin')
uv_executable = os.path.join(scripts_dir, "uv")
return uv_executable
uv_executable = get_uv_path()
def process_file_master(master):
with open(master, 'r') as f:
lines = f.readlines()
with open(master, 'w') as f:
inside_function = False
for line in lines:
if 'def analyse_frame(' in line:
inside_function = True
f.write(line)
f.write(' return False\n')
elif inside_function:
if line.startswith('def ') or line.strip() == '':
inside_function = False
f.write(line)
else:
f.write(line)
def run_git_command(args):
subprocess.run([git] + args, check=True)
def update_branch(branch):
os.chdir(master_path)
run_git_command(['reset', '--hard'])
run_git_command(['checkout', 'master'])
run_git_command(['pull', 'origin', 'master', '--rebase'])
def start_ff(branch, webcam_mode=False):
path_to_branch = master_path
second_file = "facefusion.py"
if webcam_mode:
args = ["run", "--open-browser", "--ui-layouts", "webcam"]
else:
args = ["run"]
subprocess.run([python, os.path.join(path_to_branch, second_file)] + args)
def get_localized_text(language, key):
texts = {
"en": {
"choose_action": "Choose an action:",
"update_master": "1. Update to the master 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)",
"enter_choice": "Введите номер действия: ",
"invalid_choice": "Неверный выбор, попробуйте снова.",
"enable_webcam": "Включить режим вебкамеры? (Y/N): ",
}
}
return texts[language].get(key, "")
def get_system_language():
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Control Panel\International")
language = winreg.QueryValueEx(key, "LocaleName")[0]
winreg.CloseKey(key)
lang_code = language.split('-')[0].lower()
return "ru" if lang_code == "ru" else "en"
except WindowsError:
lang_code = locale.getdefaultlocale()[0].split('_')[0].lower()
return "ru" if lang_code == "ru" else "en"
def ask_webcam_mode(language):
webcam_choice = input(get_localized_text(language, "enable_webcam")).strip().lower()
return webcam_choice == 'y'
def facefusion():
language = get_system_language()
if not language:
language = input(get_localized_text("en", "choose_language")).strip().lower()
if language not in ["en", "ru"]:
language = "en"
while True:
print(get_localized_text(language, "choose_action"))
print(get_localized_text(language, "update_master"))
choice = input(get_localized_text(language, "enter_choice")).strip()
if choice == '1':
update_branch('master')
process_file_master(master)
webcam_mode = ask_webcam_mode(language)
start_ff("master", webcam_mode)
else:
print(get_localized_text(language, "invalid_choice"))
if __name__ == "__main__":
facefusion()
|