Spaces:
Sleeping
Sleeping
File size: 2,699 Bytes
11695a5 21e3880 11695a5 beb6e6e 21e3880 11695a5 21e3880 11695a5 98cdd7e 21e3880 11695a5 21e3880 |
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 52 53 54 55 56 57 58 59 60 |
import gradio as gr
from reader import Reader
from utils import *
import shutil
from pathlib import Path
from typing import Union
OUTPUT_FOLDER = 'ag4mout'
def geogeosolver(question:str, model:str="gpt-4o-mini"):
if model == 'gpt-4o-mini':
get_github_token()
elif model == 'gemma2-9b-it':
get_grog_api()
reader = Reader(model=model)
input = translate(question)
reader.main(input)
run_ag()
image_path = f'{OUTPUT_FOLDER}/output.png'
result_dict = read_solution()
key_list = list(result_dict.keys())
premises = result_dict[key_list[0]]
constructions = result_dict[key_list[1]]
steps = result_dict[key_list[2]]
return image_path, premises, constructions, steps
def clear_directory(directory_path: Union[str, Path] = OUTPUT_FOLDER) -> None:
"""Irreversibly removes all files and folders inside the specified
directory. Returns a list with paths Python lacks permission to delete."""
# erroneous_paths = []
for path_object in Path(directory_path).iterdir():
try:
if path_object.is_dir():
shutil.rmtree(path_object)
else:
path_object.unlink()
except PermissionError:
pass
# erroneous_paths.append(path_object)
if __name__ == '__main__':
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
question = gr.Textbox(lines=1, placeholder="Hãy nhập đề bài cần giải", label="Đề bài")
solve_button = gr.Button(value="Giải")
premises = gr.Textbox(lines=3, label="Các Giả Thuyết của Đề Bài")
constructions = gr.Textbox(lines=3, label="Các điểm được dựng thêm")
steps = gr.Textbox(lines=3, label="Các Bước Giải")
with gr.Column():
image = gr.Image(type="filepath", label="Hình Vẽ")
solve_button.click(geogeosolver, inputs=question, outputs=[image, premises, constructions, steps]).then(clear_directory)
example = gr.Examples(
examples = [
'Cho tam giác ABC nhọn, vẽ các đường cao AD, BE, CF. Gọi H là trực tâm của tam giác. Gọi M, N, P, Q lần lượt là các hình chiếu vuông góc của D lên AB, BE, CF, AC. Chứng minh: tứ giác BMND nội tiếp.',
'Cho tam giác ABC có ba góc nhọn nội tiếp đường tròn (O). Các đường cao AD, BE, CF cắt nhau tại H và cắt đường tròn (O) lần lượt tại M,N,P. Chứng minh rằng: Tứ giác CEHD nội tiếp.',
],
inputs = [question],
)
demo.launch() |