Finetuning_Dataset / clean_tag.py
Anustup's picture
Upload 13 files
4b0a67f verified
raw
history blame
1.17 kB
import os
def clean_gym_keywords(text):
# Split the text by commas
parts = [part.strip() for part in text.split(',')]
# Remove duplicate "gym" keywords
unique_parts = []
seen = False
for part in parts:
if part.lower() == 'gym':
if not seen:
unique_parts.append(part)
seen = True
else:
unique_parts.append(part)
seen = False
# Join the parts back into a single string
cleaned_text = ', '.join(unique_parts)
return cleaned_text
def process_files(folder_path):
for filename in os.listdir(folder_path):
if filename.endswith('.txt'):
file_path = os.path.join(folder_path, filename)
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
cleaned_content = clean_gym_keywords(content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(cleaned_content)
# Specify the path to the folder containing your text files
folder_path = '/home/caimera-prod/kohya_new_dataset'
process_files(folder_path)