| # from othersets import load_otherset | |
| import os | |
| # load all text files from ./other/texts, return a list of strings | |
| def load_texts(): | |
| texts = [] | |
| for filename in os.listdir('./other/texts'): | |
| with open('./other/texts/' + filename, 'r') as f: | |
| texts.append(f.read()) | |
| return texts | |
| # create a jsonl file with the text content on the 'target' column, and the humber in the 'image_relpath ' | |
| def create_jsonl(texts): | |
| with open('./other/texts.jsonl', 'w') as f: | |
| for i, text in enumerate(texts): | |
| f.write('{"image_relpath": "' + str(i+1) + '.png", "target": "' + text + '"}\n') | |
| # start the process | |
| if __name__ == '__main__': | |
| texts = load_texts() | |
| create_jsonl(texts) | |