Skip to content

Commit 1803caf

Browse files
authored
Script that fixes Mangio fork locally
0 parents  commit 1803caf

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

LOCAL_CREPE_FIX.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python local_fixes.py

local_fixes.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import sys
3+
import time
4+
5+
def insert_new_line(file_name, line_to_find, text_to_insert):
6+
lines = []
7+
with open(file_name, 'r', encoding='utf-8') as read_obj:
8+
lines = read_obj.readlines()
9+
already_exists = False
10+
with open(file_name + '.tmp', 'w', encoding='utf-8') as write_obj:
11+
for i in range(len(lines)):
12+
write_obj.write(lines[i])
13+
if lines[i].strip() == line_to_find:
14+
# If next line exists and starts with sys.path.append, skip
15+
if i+1 < len(lines) and lines[i+1].strip().startswith("sys.path.append"):
16+
print('Already fixed! Skipped adding a line...')
17+
already_exists = True
18+
break
19+
else:
20+
write_obj.write(text_to_insert + '\n')
21+
# If no existing sys.path.append line was found, replace the original file
22+
if not already_exists:
23+
os.replace(file_name + '.tmp', file_name)
24+
return True
25+
else:
26+
# If existing line was found, delete temporary file
27+
os.remove(file_name + '.tmp')
28+
return False
29+
30+
def replace_in_file(file_name, old_text, new_text):
31+
with open(file_name, 'r', encoding='utf-8') as file:
32+
file_contents = file.read()
33+
34+
if old_text in file_contents:
35+
file_contents = file_contents.replace(old_text, new_text)
36+
with open(file_name, 'w', encoding='utf-8') as file:
37+
file.write(file_contents)
38+
return True
39+
40+
return False
41+
42+
if __name__ == "__main__":
43+
current_path = os.getcwd()
44+
file_name = 'extract_f0_print.py'
45+
line_to_find = 'import numpy as np, logging'
46+
text_to_insert = "sys.path.append(r'" + current_path + "')"
47+
48+
success_1 = insert_new_line(file_name, line_to_find, text_to_insert)
49+
if success_1:
50+
print('The first operation was successful!')
51+
else:
52+
print('Skipped first operation as it was already fixed!')
53+
54+
file_name = 'infer-web.py'
55+
old_text = 'with gr.Blocks(theme=gr.themes.Soft()) as app:'
56+
new_text = 'with gr.Blocks() as app:'
57+
58+
success_2 = replace_in_file(file_name, old_text, new_text)
59+
if success_2:
60+
print('The second operation was successful!')
61+
62+
if success_1 and success_2:
63+
print('Local fixes successful! You should now be able to infer and train locally on crepe RVC.')
64+
else:
65+
print("Local fixes didn't apply? You shouldn't be seeing this if you ran it in the correct folder. Otherwise, contact kalomaze#2983 in AI HUB")
66+
67+
time.sleep(5)

0 commit comments

Comments
 (0)