File size: 1,345 Bytes
f1f2c2c | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | def output_from_text(text):
"""
Parse the text to extract the number of objects and the path.
Splits the text by commas and removes leading and trailing whitespace from each element.
"""
try:
lines = text.strip().split("\n")
if len(lines) < 2:
out_line = lines[-1].strip()
else:
out_line = lines[-2].strip()
path = [item.strip() for item in out_line.split(",")]
if len(path) < 2:
out_line = lines[-1].strip()
path = [item.strip() for item in out_line.split(",")]
return {
"OUTPUT": path,
"ERROR": None
}
except Exception as e:
return {
"OUTPUT": None,
"ERROR": str(e)
}
import os
import json
def gold_to_output(i):
gold_output = None
try:
#get directory of this file
dir_of_file = os.path.dirname(os.path.realpath(__file__))
#open the data file
with open(dir_of_file + "\data.json") as f:
data = json.load(f)
row = data[i]
path = row['path']
output_prompt = ",".join(path)
except Exception as e:
return {
"OUTPUT": None,
"ERROR": str(e)
}
return {
"OUTPUT": output_prompt,
"ERROR": None
} |