File size: 722 Bytes
3c21fb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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)