| import os |
|
|
| def clean_gym_keywords(text): |
| |
| parts = [part.strip() for part in text.split(',')] |
| |
| |
| 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 |
| |
| |
| 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) |
|
|
| |
| folder_path = '/home/caimera-prod/kohya_new_dataset' |
| process_files(folder_path) |
|
|