Spaces:
Runtime error
Runtime error
Integrate business logic
Browse files
app.css
CHANGED
|
@@ -39,7 +39,7 @@
|
|
| 39 |
.probelm-example-another {
|
| 40 |
position: absolute;
|
| 41 |
top: 0;
|
| 42 |
-
right:
|
| 43 |
border-left: 1px solid rgba(0, 0, 0, 0.15);
|
| 44 |
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
| 45 |
border-radius: 0 0px 0 10px;
|
|
@@ -48,6 +48,7 @@
|
|
| 48 |
justify-content: center;
|
| 49 |
height: 28.49px;
|
| 50 |
width: 36px;
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
.probelm-example-another > svg {
|
|
@@ -62,14 +63,15 @@
|
|
| 62 |
border-left: 1px solid rgba(0, 0, 0, 0.15);
|
| 63 |
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
| 64 |
border-radius: 0 10px 0 0px;
|
| 65 |
-
padding: 4px
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
.right {
|
| 69 |
border: 1px solid rgba(0, 0, 0, 0.15);
|
| 70 |
border-radius: 10px;
|
| 71 |
position: relative;
|
| 72 |
-
padding:
|
| 73 |
min-height: 500px;
|
| 74 |
}
|
| 75 |
|
|
@@ -86,4 +88,6 @@
|
|
| 86 |
.solution-content {
|
| 87 |
border-radius: 10px;
|
| 88 |
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
|
|
|
|
|
| 89 |
}
|
|
|
|
| 39 |
.probelm-example-another {
|
| 40 |
position: absolute;
|
| 41 |
top: 0;
|
| 42 |
+
right: 27.4px;
|
| 43 |
border-left: 1px solid rgba(0, 0, 0, 0.15);
|
| 44 |
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
| 45 |
border-radius: 0 0px 0 10px;
|
|
|
|
| 48 |
justify-content: center;
|
| 49 |
height: 28.49px;
|
| 50 |
width: 36px;
|
| 51 |
+
cursor: pointer;
|
| 52 |
}
|
| 53 |
|
| 54 |
.probelm-example-another > svg {
|
|
|
|
| 63 |
border-left: 1px solid rgba(0, 0, 0, 0.15);
|
| 64 |
border-bottom: 1px solid rgba(0, 0, 0, 0.15);
|
| 65 |
border-radius: 0 10px 0 0px;
|
| 66 |
+
padding: 4px 12px;
|
| 67 |
+
cursor: pointer;
|
| 68 |
}
|
| 69 |
|
| 70 |
.right {
|
| 71 |
border: 1px solid rgba(0, 0, 0, 0.15);
|
| 72 |
border-radius: 10px;
|
| 73 |
position: relative;
|
| 74 |
+
padding: 40px 14px 14px 14px;
|
| 75 |
min-height: 500px;
|
| 76 |
}
|
| 77 |
|
|
|
|
| 88 |
.solution-content {
|
| 89 |
border-radius: 10px;
|
| 90 |
border: 1px solid rgba(0, 0, 0, 0.15);
|
| 91 |
+
height: 480px;
|
| 92 |
+
overflow-y: visible;
|
| 93 |
}
|
app.py
CHANGED
|
@@ -724,42 +724,39 @@ example_data = datasets.load_dataset(
|
|
| 724 |
)
|
| 725 |
|
| 726 |
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
|
| 732 |
|
| 733 |
-
def
|
|
|
|
|
|
|
| 734 |
return problem
|
| 735 |
|
| 736 |
|
| 737 |
-
def
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
problem_2_text[:100] + "..." if len(problem_2_text) > 100 else problem_2_text,
|
| 742 |
-
problem_1_text,
|
| 743 |
-
problem_2_text,
|
| 744 |
)
|
|
|
|
| 745 |
|
| 746 |
|
| 747 |
def clear():
|
| 748 |
-
|
| 749 |
-
return "", 0.1, "",
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
with open("app.css", "r") as f:
|
| 753 |
-
css = f.read()
|
| 754 |
-
|
| 755 |
-
with open("./static/icon/reset.svg", "r") as f:
|
| 756 |
-
reset_svg = f.read()
|
| 757 |
|
| 758 |
-
latex_delimiters = [
|
| 759 |
-
{"left": "[", "right": "]", "display": True},
|
| 760 |
-
]
|
| 761 |
|
| 762 |
with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
|
|
|
|
|
|
|
| 763 |
with gr.Row(elem_classes="title"):
|
| 764 |
gr.HTML("Math Olympiad Solver", elem_classes="title-content")
|
| 765 |
|
|
@@ -770,15 +767,15 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
|
|
| 770 |
with gr.Column(scale=1, elem_classes="left"):
|
| 771 |
with gr.Row(elem_classes="probelm-example-container"):
|
| 772 |
with gr.Blocks(elem_classes="probelm-example-title"):
|
| 773 |
-
gr.HTML(
|
| 774 |
|
| 775 |
with gr.Blocks(elem_classes="action-container"):
|
| 776 |
-
gr.
|
| 777 |
-
gr.
|
| 778 |
|
| 779 |
with gr.Row(elem_classes="copy-icon-container"):
|
| 780 |
-
gr.Markdown(
|
| 781 |
-
|
| 782 |
latex_delimiters=latex_delimiters,
|
| 783 |
elem_classes="probelm-example-content",
|
| 784 |
)
|
|
@@ -789,12 +786,38 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
|
|
| 789 |
temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
|
| 790 |
|
| 791 |
with gr.Row():
|
| 792 |
-
|
| 793 |
btn_clear = gr.Button("Clear")
|
| 794 |
|
| 795 |
with gr.Column(scale=1, elem_classes="right"):
|
| 796 |
gr.HTML("Solution", elem_classes="solution-title-content")
|
| 797 |
out = gr.Markdown(elem_classes="solution-content", latex_delimiters=latex_delimiters)
|
| 798 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
if __name__ == "__main__":
|
| 800 |
demo.queue(default_concurrency_limit=5).launch()
|
|
|
|
| 724 |
)
|
| 725 |
|
| 726 |
|
| 727 |
+
with open("app.css", "r") as f:
|
| 728 |
+
css = f.read()
|
| 729 |
+
|
| 730 |
+
with open("./static/icon/reset.svg", "r") as f:
|
| 731 |
+
reset_svg = f.read()
|
| 732 |
+
|
| 733 |
+
latex_delimiters = [
|
| 734 |
+
{"left": "[", "right": "]", "display": True},
|
| 735 |
+
]
|
| 736 |
|
| 737 |
|
| 738 |
+
def get_random_problem():
|
| 739 |
+
example = random.choice(list(example_data))
|
| 740 |
+
problem = example["problem"]
|
| 741 |
return problem
|
| 742 |
|
| 743 |
|
| 744 |
+
def update_example_problem():
|
| 745 |
+
problem_example_text = get_random_problem()
|
| 746 |
+
problem_example_text_display = (
|
| 747 |
+
problem_example_text[:100] + "..." if len(problem_example_text) > 100 else problem_example_text
|
|
|
|
|
|
|
|
|
|
| 748 |
)
|
| 749 |
+
return problem_example_text, problem_example_text_display
|
| 750 |
|
| 751 |
|
| 752 |
def clear():
|
| 753 |
+
problem_example_text, problem_example_text_display = update_example_problem()
|
| 754 |
+
return "", 0.1, "", problem_example_text_display, problem_example_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
|
|
|
|
|
|
|
|
|
|
| 756 |
|
| 757 |
with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
|
| 758 |
+
problem_example_text, problem_example_text_display = update_example_problem()
|
| 759 |
+
|
| 760 |
with gr.Row(elem_classes="title"):
|
| 761 |
gr.HTML("Math Olympiad Solver", elem_classes="title-content")
|
| 762 |
|
|
|
|
| 767 |
with gr.Column(scale=1, elem_classes="left"):
|
| 768 |
with gr.Row(elem_classes="probelm-example-container"):
|
| 769 |
with gr.Blocks(elem_classes="probelm-example-title"):
|
| 770 |
+
gr.HTML(problem_example_text_display, elem_classes="probelm-example-title-content")
|
| 771 |
|
| 772 |
with gr.Blocks(elem_classes="action-container"):
|
| 773 |
+
gr.Button("", elem_classes="probelm-example-another", icon=reset_svg)
|
| 774 |
+
copy_btn = gr.Button("Copy", elem_classes="probelm-example-copy")
|
| 775 |
|
| 776 |
with gr.Row(elem_classes="copy-icon-container"):
|
| 777 |
+
problem_example = gr.Markdown(
|
| 778 |
+
problem_example_text_display,
|
| 779 |
latex_delimiters=latex_delimiters,
|
| 780 |
elem_classes="probelm-example-content",
|
| 781 |
)
|
|
|
|
| 786 |
temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
|
| 787 |
|
| 788 |
with gr.Row():
|
| 789 |
+
btn_run = gr.Button("Run")
|
| 790 |
btn_clear = gr.Button("Clear")
|
| 791 |
|
| 792 |
with gr.Column(scale=1, elem_classes="right"):
|
| 793 |
gr.HTML("Solution", elem_classes="solution-title-content")
|
| 794 |
out = gr.Markdown(elem_classes="solution-content", latex_delimiters=latex_delimiters)
|
| 795 |
|
| 796 |
+
problem_example_text_hidden = gr.Markdown(value=problem_example_text, visible=False)
|
| 797 |
+
btn_run.click(fn=solve_problem, inputs=[inp, temperature], outputs=out)
|
| 798 |
+
|
| 799 |
+
copy_btn.click(fn=lambda example: example, inputs=[problem_example_text_hidden], outputs=[inp])
|
| 800 |
+
|
| 801 |
+
btn_clear.click(
|
| 802 |
+
fn=clear,
|
| 803 |
+
inputs=[],
|
| 804 |
+
outputs=[
|
| 805 |
+
inp,
|
| 806 |
+
temperature,
|
| 807 |
+
out,
|
| 808 |
+
problem_example,
|
| 809 |
+
problem_example_text_hidden,
|
| 810 |
+
],
|
| 811 |
+
)
|
| 812 |
+
|
| 813 |
+
demo.load(
|
| 814 |
+
update_example_problem,
|
| 815 |
+
inputs=None,
|
| 816 |
+
outputs=[
|
| 817 |
+
problem_example,
|
| 818 |
+
problem_example_text_hidden,
|
| 819 |
+
],
|
| 820 |
+
)
|
| 821 |
+
|
| 822 |
if __name__ == "__main__":
|
| 823 |
demo.queue(default_concurrency_limit=5).launch()
|