-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_utils.py
More file actions
37 lines (31 loc) · 1.01 KB
/
file_utils.py
File metadata and controls
37 lines (31 loc) · 1.01 KB
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
37
import yaml, json, os
def load_yaml(filepath):
with open(f"{filepath}", "r") as file:
data = yaml.safe_load(file) # Use safe_load to avoid potential security issues
return data
def save_file_json(file_path, data):
with open(f'{file_path}', 'w') as g:
json.dump(data, g, indent=4)
def read_gtlabels(filepath):
'''only for decider method -- when to prompt vlm -- not actually sent in vlm prompt'''
labels = []
try:
with open(f"{filepath}", "r") as file:
for line in file:
labels.append(line.strip())
except Exception as e:
print(e)
return labels
def read_prompt(filepath):
with open(f"{filepath}", 'r') as file:
filedata = file.read()
return filedata
def read_json(filepath):
try:
with open(filepath) as json_file:
return json.load(json_file)
except Exception as e:
print(e)
def makeCheck(fol_path):
if not os.path.exists(fol_path):
os.makedirs(fol_path)