ranWang commited on
Commit
5fc7ca2
1 Parent(s): 37b95b3

After clear, scroll to the top

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -744,7 +744,7 @@ def update_problems():
744
  )
745
 
746
 
747
- def clear_inputs():
748
  problem_1_display, problem_2_display, problem_1_full, problem_2_full = update_problems()
749
  return "", 0.1, "", problem_1_display, problem_2_display, problem_1_full, problem_2_full
750
 
@@ -775,6 +775,12 @@ css = """
775
  }
776
  """
777
 
 
 
 
 
 
 
778
  with gr.Blocks(css=css) as demo:
779
  latex_delimiters = [
780
  {"left": "[", "right": "]", "display": True},
@@ -789,10 +795,10 @@ with gr.Blocks(css=css) as demo:
789
  problem_example_1 = gr.Markdown(value=problem_1_display, elem_classes="problem-text")
790
  copy_btn_1 = gr.Button("Copy", elem_classes="copy-button")
791
  with gr.Row(elem_classes="problem-examples-container"):
792
- gr.Markdown(
793
  value="Problem example 2", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
794
  )
795
- problem_example_2 = gr.Markdown(value=problem_2_display, elem_classes="problem-text")
796
  copy_btn_2 = gr.Button("Copy", elem_classes="copy-button")
797
 
798
  with gr.Row():
@@ -813,8 +819,10 @@ with gr.Blocks(css=css) as demo:
813
  copy_btn_1.click(fn=copy_problem_to_input, inputs=[problem_1_full_hidden], outputs=[inp])
814
  copy_btn_2.click(fn=copy_problem_to_input, inputs=[problem_2_full_hidden], outputs=[inp])
815
 
 
 
816
  btn_clear.click(
817
- fn=clear_inputs,
818
  inputs=[],
819
  outputs=[
820
  inp,
 
744
  )
745
 
746
 
747
+ def clear():
748
  problem_1_display, problem_2_display, problem_1_full, problem_2_full = update_problems()
749
  return "", 0.1, "", problem_1_display, problem_2_display, problem_1_full, problem_2_full
750
 
 
775
  }
776
  """
777
 
778
+ js = """
779
+ function scrollToTop() {
780
+ window.scrollTo({top: 0, behavior: 'smooth'});
781
+ }
782
+ """
783
+
784
  with gr.Blocks(css=css) as demo:
785
  latex_delimiters = [
786
  {"left": "[", "right": "]", "display": True},
 
795
  problem_example_1 = gr.Markdown(value=problem_1_display, elem_classes="problem-text")
796
  copy_btn_1 = gr.Button("Copy", elem_classes="copy-button")
797
  with gr.Row(elem_classes="problem-examples-container"):
798
+ problem_example_2 = gr.Markdown(
799
  value="Problem example 2", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
800
  )
801
+ gr.Markdown(value=problem_2_display, elem_classes="problem-text")
802
  copy_btn_2 = gr.Button("Copy", elem_classes="copy-button")
803
 
804
  with gr.Row():
 
819
  copy_btn_1.click(fn=copy_problem_to_input, inputs=[problem_1_full_hidden], outputs=[inp])
820
  copy_btn_2.click(fn=copy_problem_to_input, inputs=[problem_2_full_hidden], outputs=[inp])
821
 
822
+ btn_clear.click(js=js)
823
+
824
  btn_clear.click(
825
+ fn=clear,
826
  inputs=[],
827
  outputs=[
828
  inp,