Delete updater_facefusion.py
Browse files- updater_facefusion.py +0 -200
updater_facefusion.py
DELETED
|
@@ -1,200 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
import sys
|
| 4 |
-
|
| 5 |
-
git = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'system', 'git', 'cmd', 'git.exe')
|
| 6 |
-
ff_obs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'facefusion')
|
| 7 |
-
python = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'system', 'python', 'python.exe')
|
| 8 |
-
|
| 9 |
-
files = [
|
| 10 |
-
ff_obs + "\\next" + "\\facefusion\\content_analyser.py",
|
| 11 |
-
ff_obs + "\\master" + "\\facefusion\\content_analyser.py",
|
| 12 |
-
]
|
| 13 |
-
|
| 14 |
-
def get_uv_path():
|
| 15 |
-
if sys.platform.startswith('win'):
|
| 16 |
-
scripts_dir = os.path.join(os.path.dirname(python), 'Scripts')
|
| 17 |
-
uv_executable = os.path.join(scripts_dir, "uv.exe")
|
| 18 |
-
else:
|
| 19 |
-
scripts_dir = os.path.join(os.path.dirname(os.path.dirname(python)), 'bin')
|
| 20 |
-
uv_executable = os.path.join(scripts_dir, "uv")
|
| 21 |
-
return uv_executable
|
| 22 |
-
|
| 23 |
-
uv_executable = get_uv_path()
|
| 24 |
-
|
| 25 |
-
def gradio_version(branch):
|
| 26 |
-
if branch=="master":
|
| 27 |
-
subprocess.run([python], ["-m", {uv_executable}, "pip", "install", "gradio==3.50.2"])
|
| 28 |
-
if branch=="next":
|
| 29 |
-
subprocess.run([python], ["-m", {uv_executable}, "pip", "install", "gradio==4.40.0"])
|
| 30 |
-
|
| 31 |
-
def process_file_master(file_path):
|
| 32 |
-
with open(file_path, 'r') as f:
|
| 33 |
-
lines = f.readlines()
|
| 34 |
-
with open(file_path, 'w') as f:
|
| 35 |
-
inside_function = False
|
| 36 |
-
for line in lines:
|
| 37 |
-
if 'def analyse_frame(' in line:
|
| 38 |
-
inside_function = True
|
| 39 |
-
f.write(line)
|
| 40 |
-
f.write(' return False\n')
|
| 41 |
-
elif inside_function:
|
| 42 |
-
if line.startswith('def ') or line.strip() == '':
|
| 43 |
-
inside_function = False
|
| 44 |
-
f.write(line)
|
| 45 |
-
else:
|
| 46 |
-
f.write(line)
|
| 47 |
-
|
| 48 |
-
def process_file_next(file_path):
|
| 49 |
-
with open(file_path, 'r') as f:
|
| 50 |
-
lines = f.readlines()
|
| 51 |
-
|
| 52 |
-
with open(file_path, 'w') as f:
|
| 53 |
-
inside_function = False
|
| 54 |
-
current_function = None
|
| 55 |
-
|
| 56 |
-
for line in lines:
|
| 57 |
-
if 'def analyse_frame(' in line:
|
| 58 |
-
inside_function = True
|
| 59 |
-
current_function = 'analyse_frame'
|
| 60 |
-
f.write(line)
|
| 61 |
-
f.write(' return False\n\n')
|
| 62 |
-
elif 'def forward(' in line:
|
| 63 |
-
inside_function = True
|
| 64 |
-
current_function = 'forward'
|
| 65 |
-
f.write(line)
|
| 66 |
-
f.write(' return 0\n\n')
|
| 67 |
-
elif inside_function:
|
| 68 |
-
if line.startswith('def '):
|
| 69 |
-
inside_function = False
|
| 70 |
-
current_function = None
|
| 71 |
-
f.write(line)
|
| 72 |
-
elif line.strip() == '':
|
| 73 |
-
continue
|
| 74 |
-
else:
|
| 75 |
-
f.write(line)
|
| 76 |
-
|
| 77 |
-
def process_files(files):
|
| 78 |
-
for file_path in files:
|
| 79 |
-
if '\\next\\' in file_path:
|
| 80 |
-
process_file_next(file_path)
|
| 81 |
-
elif '\\master\\' in file_path:
|
| 82 |
-
process_file_master(file_path)
|
| 83 |
-
|
| 84 |
-
def run_git_command(args):
|
| 85 |
-
subprocess.run([git] + args, check=True)
|
| 86 |
-
|
| 87 |
-
def update_branch(branch):
|
| 88 |
-
if branch=="master":
|
| 89 |
-
os.chdir(ff_obs + "\\master")
|
| 90 |
-
if branch=="next":
|
| 91 |
-
os.chdir(ff_obs + "\\next")
|
| 92 |
-
run_git_command(['reset', '--hard'])
|
| 93 |
-
run_git_command(['checkout', branch])
|
| 94 |
-
run_git_command(['pull', 'origin', branch, '--rebase'])
|
| 95 |
-
|
| 96 |
-
def start_ff(branch, webcam_mode=False):
|
| 97 |
-
if branch=="master":
|
| 98 |
-
path_to_branch = os.path.join(ff_obs + "\\master")
|
| 99 |
-
if branch=="next":
|
| 100 |
-
path_to_branch = os.path.join(ff_obs + "\\next")
|
| 101 |
-
|
| 102 |
-
if branch=="next":
|
| 103 |
-
py_files = [f for f in os.listdir(path_to_branch) if f.endswith('.py')]
|
| 104 |
-
if len(py_files) != 2:
|
| 105 |
-
return
|
| 106 |
-
second_file = [f for f in py_files if f != 'installer.py'][0]
|
| 107 |
-
if branch=="master":
|
| 108 |
-
second_file = "run.py"
|
| 109 |
-
|
| 110 |
-
if webcam_mode:
|
| 111 |
-
if branch=="next":
|
| 112 |
-
args_next = ["run"]
|
| 113 |
-
args = ["--open-browser", "--ui-layouts", "webcam"]
|
| 114 |
-
args = args_next + args
|
| 115 |
-
if branch=="master":
|
| 116 |
-
args = ["--open-browser", "--ui-layouts", "webcam"]
|
| 117 |
-
else:
|
| 118 |
-
if branch=="next":
|
| 119 |
-
args_next = ["run"]
|
| 120 |
-
args = ["--open-browser"]
|
| 121 |
-
args = args_next+args
|
| 122 |
-
if branch=="master":
|
| 123 |
-
args = ["--open-browser"]
|
| 124 |
-
|
| 125 |
-
subprocess.run([python, os.path.join(path_to_branch, second_file)] + args)
|
| 126 |
-
|
| 127 |
-
def get_localized_text(language, key):
|
| 128 |
-
texts = {
|
| 129 |
-
"en": {
|
| 130 |
-
"choose_action": "Choose an action:",
|
| 131 |
-
"update_master": "1. Update to the master branch and start it",
|
| 132 |
-
"update_next": "2. Update to the next branch and start it",
|
| 133 |
-
"start_facefusion": "3. Start facefusion",
|
| 134 |
-
"enter_choice": "Enter the number of the action: ",
|
| 135 |
-
"invalid_choice": "Invalid choice, please try again.",
|
| 136 |
-
"choose_language": "Choose a language (en/ru): ",
|
| 137 |
-
"enable_webcam": "Enable webcam mode? (Y/N): ",
|
| 138 |
-
},
|
| 139 |
-
"ru": {
|
| 140 |
-
"choose_action": "Выберите действие:",
|
| 141 |
-
"update_master": "1. Обновить до обычной ветки и запустить ее (master)",
|
| 142 |
-
"update_next": "2. Обновить до ветки next и запустить ее",
|
| 143 |
-
"start_facefusion": "3. Запустить facefusion",
|
| 144 |
-
"enter_choice": "Введите номер действия: ",
|
| 145 |
-
"invalid_choice": "Неверный выбор, попробуйте снова.",
|
| 146 |
-
"choose_language": "Выберите язык (en/ru): ",
|
| 147 |
-
"enable_webcam": "Включить режим вебкамеры? (Y/N): ",
|
| 148 |
-
}
|
| 149 |
-
}
|
| 150 |
-
return texts[language].get(key, "")
|
| 151 |
-
|
| 152 |
-
def read_language_from_file(file_path):
|
| 153 |
-
if os.path.exists(file_path):
|
| 154 |
-
with open(file_path, 'r', encoding='utf-8') as file:
|
| 155 |
-
language = file.read().strip().lower()
|
| 156 |
-
if language in ["en", "ru"]:
|
| 157 |
-
return language
|
| 158 |
-
return None
|
| 159 |
-
|
| 160 |
-
def write_language_to_file(file_path, language):
|
| 161 |
-
with open(file_path, 'w', encoding='utf-8') as file:
|
| 162 |
-
file.write(language)
|
| 163 |
-
|
| 164 |
-
def ask_webcam_mode(language):
|
| 165 |
-
webcam_choice = input(get_localized_text(language, "enable_webcam")).strip().lower()
|
| 166 |
-
return webcam_choice == 'y'
|
| 167 |
-
|
| 168 |
-
def facefusion():
|
| 169 |
-
file_path = 'lang.txt'
|
| 170 |
-
language = read_language_from_file(file_path)
|
| 171 |
-
if not language:
|
| 172 |
-
language = input(get_localized_text("en", "choose_language")).strip().lower()
|
| 173 |
-
if language not in ["en", "ru"]:
|
| 174 |
-
language = "en"
|
| 175 |
-
write_language_to_file(file_path, language)
|
| 176 |
-
|
| 177 |
-
while True:
|
| 178 |
-
print(get_localized_text(language, "choose_action"))
|
| 179 |
-
print(get_localized_text(language, "update_master"))
|
| 180 |
-
print(get_localized_text(language, "update_next"))
|
| 181 |
-
|
| 182 |
-
choice = input(get_localized_text(language, "enter_choice")).strip()
|
| 183 |
-
|
| 184 |
-
if choice == '1':
|
| 185 |
-
update_branch('master')
|
| 186 |
-
process_files(files)
|
| 187 |
-
gradio_version('master')
|
| 188 |
-
webcam_mode = ask_webcam_mode(language)
|
| 189 |
-
start_ff("master", webcam_mode)
|
| 190 |
-
elif choice == '2':
|
| 191 |
-
update_branch('next')
|
| 192 |
-
process_files(files)
|
| 193 |
-
gradio_version('next')
|
| 194 |
-
webcam_mode = ask_webcam_mode(language)
|
| 195 |
-
start_ff("next", webcam_mode)
|
| 196 |
-
else:
|
| 197 |
-
print(get_localized_text(language, "invalid_choice"))
|
| 198 |
-
|
| 199 |
-
if __name__ == "__main__":
|
| 200 |
-
facefusion()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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