-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3intepretation.py
46 lines (38 loc) · 1.23 KB
/
3intepretation.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
37
38
39
40
41
42
43
44
45
46
import os
from functools import partial
import traceback
import time
#import PIL.Image
#from PIL import Image
import json
import pickle
from tqdm import tqdm
from engine.utils import ProgramGenerator
from prompts.gqa_interpretation import create_prompt
os.environ['OPENAI_API_KEY'] = 'Your OpenAI API key'
if __name__ == '__main__':
processes = json.load(open("dataset/processed_data/processes.json"))
questions = json.load(open("dataset/SME_test.json"))
prompter = partial(create_prompt, method='all')
generator = ProgramGenerator(prompter=prompter)
explanation = {}
qids = list(processes.keys())
for k in tqdm(qids):
p = processes[k]
q = p['question']
try:
process = p['process']
except:
explanation[k] = ''
continue
question = questions[k]
while True:
try:
exp, _ = generator.generate(dict(question=question, program=process))
break
except:
traceback.print_exc()
time.sleep(5)
explanation[k] = exp
with open("results/generated_explanations.json", "w") as f:
json.dump(explanation, f)