GeoGenSolver / utils.py
HugoVoxx's picture
Update utils.py
fb4253b verified
raw
history blame
1.36 kB
import subprocess, os
import regex as re
from deep_translator import GoogleTranslator
def get_grog_api():
return os.get_env("GROQ_API_KEY")
def get_github_token():
return os.get_env("GITHUB_TOKEN")
def translate(input:str) -> str:
translated = GoogleTranslator(source='vi', target='en').translate(text=input)
return translated
def run_ag():
subprocess.run(["ag4masses/utils/run.sh"])
def read_solution():
with open('ag4mout/solution.out', 'r', encoding='utf-8') as f:
lines = f.readlines()
paragraphs = ''.join(lines).split('\n\n')
theorem_premises = paragraphs[0].strip()
auxiliary_constructions = paragraphs[1].strip()
proof_steps = paragraphs[2].strip()
proof_steps = re.sub(r'\d+\. ', '- Ta có:\n', proof_steps)
proof_steps = re.sub(r' & ', '\n', proof_steps)
proof_steps = re.sub(r' ⇒ ', '\n⇒ ', proof_steps)
result = {
theorem_premises.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(theorem_premises.split('\n')[1:])),
auxiliary_constructions.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(auxiliary_constructions.split('\n')[1:])),
proof_steps.split('\n')[0]: GoogleTranslator(target='vi').translate(text='\n'.join(proof_steps.split('\n')[1:]))
}
return result