Update captions_code.py
Browse files- captions_code.py +8 -6
captions_code.py
CHANGED
@@ -9,6 +9,7 @@ import os
|
|
9 |
keyword = "" # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
|
10 |
path = r"" # Path where the captions are, for example: path = r"C:\my model\captions"
|
11 |
change_parenthesis = True # Replaces ( ... ) with \( ... \)
|
|
|
12 |
|
13 |
# The program will not replace underscores in these tags. It's not necessary to add your keyword
|
14 |
not_touch = [
|
@@ -84,12 +85,13 @@ for file in os.listdir(path):
|
|
84 |
with open(file_path, 'r') as f:
|
85 |
text = f.read()
|
86 |
text = text.replace("\n", ", ")
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
93 |
for bad_tag in remove:
|
94 |
if bad_tag in text:
|
95 |
text = text.replace(f", {bad_tag}", "")
|
|
|
9 |
keyword = "" # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
|
10 |
path = r"" # Path where the captions are, for example: path = r"C:\my model\captions"
|
11 |
change_parenthesis = True # Replaces ( ... ) with \( ... \)
|
12 |
+
change_underscore = True # Replaces underscores with spaces
|
13 |
|
14 |
# The program will not replace underscores in these tags. It's not necessary to add your keyword
|
15 |
not_touch = [
|
|
|
85 |
with open(file_path, 'r') as f:
|
86 |
text = f.read()
|
87 |
text = text.replace("\n", ", ")
|
88 |
+
if change_underscore:
|
89 |
+
for tag in not_touch:
|
90 |
+
if tag in text:
|
91 |
+
newtag = tag.replace("_", "/$")
|
92 |
+
text = text.replace(f"{tag}", f"{newtag}")
|
93 |
+
text = text.replace("_", " ")
|
94 |
+
text = text.replace("/$", "_")
|
95 |
for bad_tag in remove:
|
96 |
if bad_tag in text:
|
97 |
text = text.replace(f", {bad_tag}", "")
|