Spaces:
Runtime error
Runtime error
So that each time you open it, you will see a different problem example.
Browse files
app.py
CHANGED
|
@@ -738,6 +738,16 @@ def copy_problem_to_input(problem):
|
|
| 738 |
return problem
|
| 739 |
|
| 740 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
css = """
|
| 742 |
.top-margin {
|
| 743 |
margin-top: 20px;
|
|
@@ -778,21 +788,19 @@ with gr.Blocks(css=css) as demo:
|
|
| 778 |
{"left": "[", "right": "]", "display": True},
|
| 779 |
]
|
| 780 |
|
| 781 |
-
|
| 782 |
|
| 783 |
with gr.Row(elem_classes="problem-container"):
|
| 784 |
gr.Markdown(
|
| 785 |
value="Problem example 1", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
|
| 786 |
)
|
| 787 |
-
|
| 788 |
-
problem_1 = gr.Markdown(value=problem_1_text_contract, latex_delimiters=latex_delimiters)
|
| 789 |
copy_btn_1 = gr.Button("Copy", elem_classes="copy-button")
|
| 790 |
with gr.Row(elem_classes="problem-container"):
|
| 791 |
gr.Markdown(
|
| 792 |
value="Problem example 2", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
|
| 793 |
)
|
| 794 |
-
|
| 795 |
-
problem_2 = gr.Markdown(value=problem_2_text_contract, latex_delimiters=latex_delimiters)
|
| 796 |
copy_btn_2 = gr.Button("Copy", elem_classes="copy-button")
|
| 797 |
|
| 798 |
with gr.Row():
|
|
@@ -807,8 +815,19 @@ with gr.Blocks(css=css) as demo:
|
|
| 807 |
|
| 808 |
btn.click(fn=solve_problem, inputs=[inp, temperature], outputs=out)
|
| 809 |
btn_clear.click(fn=clear_inputs, inputs=[], outputs=[inp, temperature, out])
|
| 810 |
-
copy_btn_1.click(fn=copy_problem_to_input, inputs=[gr.Markdown(value=
|
| 811 |
-
copy_btn_2.click(fn=copy_problem_to_input, inputs=[gr.Markdown(value=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 812 |
|
| 813 |
|
| 814 |
if __name__ == "__main__":
|
|
|
|
| 738 |
return problem
|
| 739 |
|
| 740 |
|
| 741 |
+
def update_problems():
|
| 742 |
+
problem_1_text, problem_2_text = get_random_problems()
|
| 743 |
+
return (
|
| 744 |
+
problem_1_text[:100] + "..." if len(problem_1_text) > 100 else problem_1_text,
|
| 745 |
+
problem_2_text[:100] + "..." if len(problem_2_text) > 100 else problem_2_text,
|
| 746 |
+
problem_1_text,
|
| 747 |
+
problem_2_text,
|
| 748 |
+
)
|
| 749 |
+
|
| 750 |
+
|
| 751 |
css = """
|
| 752 |
.top-margin {
|
| 753 |
margin-top: 20px;
|
|
|
|
| 788 |
{"left": "[", "right": "]", "display": True},
|
| 789 |
]
|
| 790 |
|
| 791 |
+
problem_1_display, problem_2_display, problem_1_full, problem_2_full = update_problems()
|
| 792 |
|
| 793 |
with gr.Row(elem_classes="problem-container"):
|
| 794 |
gr.Markdown(
|
| 795 |
value="Problem example 1", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
|
| 796 |
)
|
| 797 |
+
problem_1 = gr.Markdown(value=problem_1_display, elem_classes="problem-text")
|
|
|
|
| 798 |
copy_btn_1 = gr.Button("Copy", elem_classes="copy-button")
|
| 799 |
with gr.Row(elem_classes="problem-container"):
|
| 800 |
gr.Markdown(
|
| 801 |
value="Problem example 2", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
|
| 802 |
)
|
| 803 |
+
problem_2 = gr.Markdown(value=problem_2_display, elem_classes="problem-text")
|
|
|
|
| 804 |
copy_btn_2 = gr.Button("Copy", elem_classes="copy-button")
|
| 805 |
|
| 806 |
with gr.Row():
|
|
|
|
| 815 |
|
| 816 |
btn.click(fn=solve_problem, inputs=[inp, temperature], outputs=out)
|
| 817 |
btn_clear.click(fn=clear_inputs, inputs=[], outputs=[inp, temperature, out])
|
| 818 |
+
copy_btn_1.click(fn=copy_problem_to_input, inputs=[gr.Markdown(value=problem_1_full, visible=False)], outputs=[inp])
|
| 819 |
+
copy_btn_2.click(fn=copy_problem_to_input, inputs=[gr.Markdown(value=problem_2_full, visible=False)], outputs=[inp])
|
| 820 |
+
|
| 821 |
+
demo.load(
|
| 822 |
+
update_problems,
|
| 823 |
+
inputs=None,
|
| 824 |
+
outputs=[
|
| 825 |
+
problem_1,
|
| 826 |
+
problem_2,
|
| 827 |
+
gr.Markdown(value=problem_1_full, visible=False),
|
| 828 |
+
gr.Markdown(value=problem_2_full, visible=False),
|
| 829 |
+
],
|
| 830 |
+
)
|
| 831 |
|
| 832 |
|
| 833 |
if __name__ == "__main__":
|