NeuroDonu commited on
Commit
d94c15e
·
verified ·
1 Parent(s): d590300

Update updater_facefusion.py

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