Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from reader import Reader
|
| 3 |
from utils import *
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
OUTPUT_FOLDER = 'ag4mout'
|
| 6 |
|
| 7 |
def geogeosolver(question:str, model:str="gpt-4o-mini"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
reader = Reader(model=model)
|
| 9 |
input = translate(question)
|
| 10 |
reader.main(input)
|
|
@@ -17,6 +24,20 @@ def geogeosolver(question:str, model:str="gpt-4o-mini"):
|
|
| 17 |
steps = result_dict[key_list[2]]
|
| 18 |
return image_path, premises, constructions, steps
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if __name__ == '__main__':
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
with gr.Row():
|
|
@@ -28,7 +49,7 @@ if __name__ == '__main__':
|
|
| 28 |
steps = gr.Textbox(lines=3, label="Các Bước Giải")
|
| 29 |
with gr.Column():
|
| 30 |
image = gr.Image(type="filepath", label="Hình Vẽ")
|
| 31 |
-
solve_button.click(geogeosolver, inputs=question, outputs=[image, premises, constructions, steps])
|
| 32 |
example = gr.Examples(
|
| 33 |
examples = [
|
| 34 |
'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.',
|
|
@@ -36,4 +57,4 @@ if __name__ == '__main__':
|
|
| 36 |
],
|
| 37 |
inputs = [question],
|
| 38 |
)
|
| 39 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from reader import Reader
|
| 3 |
from utils import *
|
| 4 |
+
import shutil
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Union
|
| 7 |
|
| 8 |
OUTPUT_FOLDER = 'ag4mout'
|
| 9 |
|
| 10 |
def geogeosolver(question:str, model:str="gpt-4o-mini"):
|
| 11 |
+
if model == 'gpt-4o-mini':
|
| 12 |
+
get_github_token()
|
| 13 |
+
elif model == 'gemma2-9b-it':
|
| 14 |
+
get_grog_api()
|
| 15 |
reader = Reader(model=model)
|
| 16 |
input = translate(question)
|
| 17 |
reader.main(input)
|
|
|
|
| 24 |
steps = result_dict[key_list[2]]
|
| 25 |
return image_path, premises, constructions, steps
|
| 26 |
|
| 27 |
+
def clear_directory(directory_path: Union[str, Path] = OUTPUT_FOLDER) -> None:
|
| 28 |
+
"""Irreversibly removes all files and folders inside the specified
|
| 29 |
+
directory. Returns a list with paths Python lacks permission to delete."""
|
| 30 |
+
# erroneous_paths = []
|
| 31 |
+
for path_object in Path(directory_path).iterdir():
|
| 32 |
+
try:
|
| 33 |
+
if path_object.is_dir():
|
| 34 |
+
shutil.rmtree(path_object)
|
| 35 |
+
else:
|
| 36 |
+
path_object.unlink()
|
| 37 |
+
except PermissionError:
|
| 38 |
+
pass
|
| 39 |
+
# erroneous_paths.append(path_object)
|
| 40 |
+
|
| 41 |
if __name__ == '__main__':
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
with gr.Row():
|
|
|
|
| 49 |
steps = gr.Textbox(lines=3, label="Các Bước Giải")
|
| 50 |
with gr.Column():
|
| 51 |
image = gr.Image(type="filepath", label="Hình Vẽ")
|
| 52 |
+
solve_button.click(geogeosolver, inputs=question, outputs=[image, premises, constructions, steps]).then(clear_directory)
|
| 53 |
example = gr.Examples(
|
| 54 |
examples = [
|
| 55 |
'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.',
|
|
|
|
| 57 |
],
|
| 58 |
inputs = [question],
|
| 59 |
)
|
| 60 |
+
demo.launch()
|