cosk commited on
Commit
cf8cd8c
1 Parent(s): f48a716

Update captions_code.py

Browse files
Files changed (1) hide show
  1. captions_code.py +5 -1
captions_code.py CHANGED
@@ -8,6 +8,7 @@ import os
8
 
9
  get_path = str(input("Path (folder containing the captions): ")) # Path where the captions are, for example: path = r"C:\my model\captions"
10
  keyword = str(input("Keyword (adds word to all files, leave empty for none): ")) # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
 
11
  underscore = int(input("Replace underscores with spaces? (0 -> No, 1 -> Yes): ")) # Replaces underscores with spaces
12
  parenthesis = int(input("Replace parenthesis? (0 -> No, 1 -> Yes): ")) # Replaces ( ... ) with \( ... \)
13
  path = rf"{get_path}"
@@ -85,7 +86,8 @@ for file in os.listdir(path):
85
  if file_path.endswith(".txt"):
86
  with open(file_path, 'r') as f:
87
  text = f.read()
88
- text = text.replace("\n", ", ")
 
89
  if underscore == 1:
90
  for tag in not_touch:
91
  if tag in text:
@@ -101,6 +103,8 @@ for file in os.listdir(path):
101
  if parenthesis == 1:
102
  text = text.replace("(", "\(")
103
  text = text.replace(")", "\)")
 
 
104
  with open(file_path, 'w') as f:
105
  if keyword == "": text = text[:-2]
106
  if text[0] == "," and text[1] == " ":
 
8
 
9
  get_path = str(input("Path (folder containing the captions): ")) # Path where the captions are, for example: path = r"C:\my model\captions"
10
  keyword = str(input("Keyword (adds word to all files, leave empty for none): ")) # If you want to put a specific keyword on the tags, for example: keyword = "asuna"
11
+ fix_spacing = int(input("Remove line breaks? (0 -> No, 1 -> Yes): ")) # To remove line breaks, useful when downloading with gallery-dl
12
  underscore = int(input("Replace underscores with spaces? (0 -> No, 1 -> Yes): ")) # Replaces underscores with spaces
13
  parenthesis = int(input("Replace parenthesis? (0 -> No, 1 -> Yes): ")) # Replaces ( ... ) with \( ... \)
14
  path = rf"{get_path}"
 
86
  if file_path.endswith(".txt"):
87
  with open(file_path, 'r') as f:
88
  text = f.read()
89
+ if fix_spacing == 1:
90
+ text = text.replace("\n", ", ")
91
  if underscore == 1:
92
  for tag in not_touch:
93
  if tag in text:
 
103
  if parenthesis == 1:
104
  text = text.replace("(", "\(")
105
  text = text.replace(")", "\)")
106
+ if fix_spacing != 1:
107
+ text = text.replace("\n\n", "\n")
108
  with open(file_path, 'w') as f:
109
  if keyword == "": text = text[:-2]
110
  if text[0] == "," and text[1] == " ":