-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtag_content_process.py
36 lines (25 loc) · 1.09 KB
/
tag_content_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
folder_path = '.../text-prompts'
# This folder contains original text prompt files generated by BLIP.
save_folder_path = '.../processed-text-prompts'
# This folder contains processed text prompt files (removing poor tags and adding trigger word).
files_list = os.listdir(folder_path)
files_num = len(files_list)
template = '360'
for ii in range(files_num):
file_path = os.path.join(folder_path, files_list[ii])
file_save_path = os.path.join(save_folder_path, files_list[ii])
with open(file_path, 'r', encoding='utf-8') as file:
line = file.readline()
strings = line.split(',')
string_num = len(strings)
strings_new = []
strings_new += '360-degree panoramic image, '
for jj in range(string_num):
string_processed = strings[jj].replace(' ', '')
if (string_processed.find(template) == -1):
strings_new += strings[jj]
strings_new += ','
strings_new = strings_new[:-1]
with open(file_save_path, 'w', encoding='utf-8') as updated_file:
updated_file.writelines(strings_new)