Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dataloader_mixins.py): handle encoding errors gracefully when reading files #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions toolkit/dataloader_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_caption_item(self: 'AiToolkitDataset', index):
break

if os.path.exists(prompt_path):
with open(prompt_path, 'r', encoding='utf-8') as f:
with open(prompt_path, 'r', encoding='utf-8', errors='ignore') as f:
prompt = f.read()
# check if is json
if prompt_path.endswith('.json'):
Expand Down Expand Up @@ -301,7 +301,7 @@ def load_caption(self: 'FileItemDTO', caption_dict: Union[dict, None]):
short_caption = None

if os.path.exists(prompt_path):
with open(prompt_path, 'r', encoding='utf-8') as f:
with open(prompt_path, 'r', encoding='utf-8', errors='ignore') as f:
prompt = f.read()
short_caption = None
if prompt_path.endswith('.json'):
Expand Down Expand Up @@ -1127,7 +1127,7 @@ def __init__(self: 'FileItemDTO', *args, **kwargs):
caption_path = file_path_no_ext + '.json'
if not os.path.exists(caption_path):
raise Exception(f"Error: caption file not found for poi: {caption_path}")
with open(caption_path, 'r', encoding='utf-8') as f:
with open(caption_path, 'r', encoding='utf-8', errors='ignore') as f:
json_data = json.load(f)
if 'poi' not in json_data:
print(f"Warning: poi not found in caption file: {caption_path}")
Expand Down