File size: 1,769 Bytes
78dd5ab
 
 
 
b48a21c
78dd5ab
b48a21c
78dd5ab
 
 
 
 
 
33c3023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess, os
import regex as re
from deep_translator import GoogleTranslator
def get_grog_api():
    return os.getenv("GROQ_API_KEY")
def get_github_token():
    return os.getenv("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():
    if os.path.exists('ag4mout/solution.out'):
        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
    else:
        return {"key_1": "Bài toán không thể giải được/Đề bài bị lỗi", 
                "key_2": "Bài toán không thể giải được/Đề bài bị lỗi", 
                "key_3": "Bài toán không thể giải được/Đề bài bị lỗi",
                }