ranWang commited on
Commit
590d757
1 Parent(s): d63a74b

Dynamically switch to render mode on load

Browse files
Files changed (2) hide show
  1. app.css +4 -0
  2. app.py +47 -5
app.css CHANGED
@@ -148,3 +148,7 @@
148
  transform: rotate(360deg);
149
  }
150
  }
 
 
 
 
 
148
  transform: rotate(360deg);
149
  }
150
  }
151
+
152
+ .problem-input-markdown {
153
+ padding: 18px;
154
+ }
app.py CHANGED
@@ -755,7 +755,7 @@ def update_example_problem():
755
 
756
 
757
  def clear():
758
- problem_example_text, problem_example_text_display = update_example_problem()
759
  return "", 0.1, "", problem_example_text_display, problem_example_text
760
 
761
 
@@ -763,8 +763,9 @@ running_success = False
763
 
764
  with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
765
  btn_list = []
 
766
 
767
- problem_example_text, problem_example_text_display = update_example_problem()
768
 
769
  with gr.Row(elem_classes="title"):
770
  gr.HTML("Math Olympiad Solver", elem_classes="title-content")
@@ -787,12 +788,25 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
787
  copy_btn = gr.Button("Copy", elem_classes="probelm-example-copy")
788
 
789
  with gr.Row(elem_classes="copy-icon-container"):
790
- problem_example = gr.HTML(
791
  problem_example_text_display,
 
792
  elem_classes="probelm-example-content",
793
  )
794
 
795
- inp = gr.Textbox(placeholder="Problem", label="Problem input", lines=5)
 
 
 
 
 
 
 
 
 
 
 
 
796
 
797
  with gr.Accordion("Advanced Options", open=False):
798
  temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
@@ -805,7 +819,13 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
805
 
806
  with gr.Column(scale=1, elem_classes="right"):
807
  gr.HTML("Solution", elem_classes="solution-title-content")
808
- out = gr.Markdown(elem_classes="solution-content", latex_delimiters=latex_delimiters)
 
 
 
 
 
 
809
 
810
  problem_example_text_hidden = gr.Markdown(value=problem_example_text, visible=False)
811
 
@@ -820,6 +840,26 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
820
  def mount_run_btn(btn):
821
  btn.click(fn=solve_problem_wrapper, inputs=[inp, temperature], outputs=out)
822
  btn.click(get_running_btns, None, outputs=btn_list)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
 
824
  def get_running_btns():
825
  global running_success
@@ -857,6 +897,8 @@ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
857
  ],
858
  )
859
 
 
 
860
  mount_run_btn(btn_run)
861
 
862
  demo.load(
 
755
 
756
 
757
  def clear():
758
+ problem_example_text_display, problem_example_text = update_example_problem()
759
  return "", 0.1, "", problem_example_text_display, problem_example_text
760
 
761
 
 
763
 
764
  with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
765
  btn_list = []
766
+ problem_input_ele_list = []
767
 
768
+ problem_example_text_display, problem_example_text = update_example_problem()
769
 
770
  with gr.Row(elem_classes="title"):
771
  gr.HTML("Math Olympiad Solver", elem_classes="title-content")
 
788
  copy_btn = gr.Button("Copy", elem_classes="probelm-example-copy")
789
 
790
  with gr.Row(elem_classes="copy-icon-container"):
791
+ problem_example = gr.Markdown(
792
  problem_example_text_display,
793
+ latex_delimiters=latex_delimiters,
794
  elem_classes="probelm-example-content",
795
  )
796
 
797
+ with gr.Row(elem_classes="probelm-input-container"):
798
+ inp = gr.Textbox(placeholder="Problem", label="Problem input", lines=5, visible=True)
799
+ problem_markdown = gr.Markdown(
800
+ visible=False,
801
+ latex_delimiters=[
802
+ {"left": "[", "right": "]", "display": True},
803
+ {"left": "$", "right": "$", "display": False},
804
+ ],
805
+ )
806
+
807
+ inp.change(fn=lambda text: text, inputs=[inp], outputs=[problem_markdown])
808
+ problem_input_ele_list.append(inp)
809
+ problem_input_ele_list.append(problem_markdown)
810
 
811
  with gr.Accordion("Advanced Options", open=False):
812
  temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
 
819
 
820
  with gr.Column(scale=1, elem_classes="right"):
821
  gr.HTML("Solution", elem_classes="solution-title-content")
822
+ out = gr.Markdown(
823
+ elem_classes="solution-content",
824
+ latex_delimiters=[
825
+ {"left": "[", "right": "]", "display": True},
826
+ {"left": "$", "right": "$", "display": False},
827
+ ],
828
+ )
829
 
830
  problem_example_text_hidden = gr.Markdown(value=problem_example_text, visible=False)
831
 
 
840
  def mount_run_btn(btn):
841
  btn.click(fn=solve_problem_wrapper, inputs=[inp, temperature], outputs=out)
842
  btn.click(get_running_btns, None, outputs=btn_list)
843
+ btn.click(get_problem_input, None, outputs=problem_input_ele_list)
844
+
845
+ def get_run_after_problem_input():
846
+ return gr.Textbox(placeholder="Problem", label="Problem input", lines=5, visible=False), gr.Markdown(
847
+ visible=True,
848
+ latex_delimiters=[
849
+ {"left": "[", "right": "]", "display": True},
850
+ {"left": "$", "right": "$", "display": False},
851
+ ],
852
+ elem_classes="problem-input-markdown",
853
+ )
854
+
855
+ def get_init_problem_input():
856
+ return gr.Textbox(placeholder="Problem", label="Problem input", lines=5, visible=True), gr.Markdown(
857
+ visible=False,
858
+ latex_delimiters=[
859
+ {"left": "[", "right": "]", "display": True},
860
+ {"left": "$", "right": "$", "display": False},
861
+ ],
862
+ )
863
 
864
  def get_running_btns():
865
  global running_success
 
897
  ],
898
  )
899
 
900
+ btn_clear.click(get_init_problem_input, None, outputs=problem_input_ele_list)
901
+
902
  mount_run_btn(btn_run)
903
 
904
  demo.load(