ranWang commited on
Commit
6f49f3d
1 Parent(s): 8e24447

update layout

Browse files
Files changed (2) hide show
  1. app.css +57 -0
  2. app.py +44 -91
app.css ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .title-content {
2
+ font-size: 24px;
3
+ font-weight: 600;
4
+ display: flex;
5
+ align-items: center;
6
+ justify-content: center;
7
+ }
8
+
9
+ .sub-title-content {
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ font-size: 18px;
14
+ }
15
+
16
+ .main-area {
17
+ border-radius: 10px;
18
+ padding: 20px;
19
+ border: 1px solid rgba(0, 0, 0, 0.15);
20
+ }
21
+
22
+ .probelm-example-container {
23
+ position: relative;
24
+ padding: 24px 8px 8px 8px;
25
+ border: 1px solid rgba(0, 0, 0, 0.15);
26
+ border-radius: 10px;
27
+ }
28
+
29
+ .probelm-example-title-content {
30
+ position: absolute;
31
+ top: 0;
32
+ left: 0;
33
+ border-right: 1px solid rgba(0, 0, 0, 0.15);
34
+ border-bottom: 1px solid rgba(0, 0, 0, 0.15);
35
+ border-radius: 10px 0 10px 0;
36
+ }
37
+
38
+ .probelm-example-another {
39
+ position: absolute;
40
+ top: 0;
41
+ right: 0;
42
+ border: 1px solid rgba(0, 0, 0, 0.15);
43
+ border-radius: 0 10px 0 10px;
44
+ }
45
+
46
+ .probelm-example-copy {
47
+ position: absolute;
48
+ top: 0;
49
+ right: 0;
50
+ border: 1px solid rgba(0, 0, 0, 0.15);
51
+ border-radius: 0 10px 0 10px;
52
+ }
53
+
54
+ .right {
55
+ border: 1px solid rgba(0, 0, 0, 0.15);
56
+ border-radius: 10px;
57
+ }
app.py CHANGED
@@ -16,10 +16,10 @@ from sympy.parsing.latex import parse_latex
16
  from openai import OpenAI
17
 
18
 
19
- client = OpenAI(
20
- base_url=os.environ.get("SERVER_URL"),
21
- api_key=os.environ.get("HF_TOKEN"),
22
- )
23
 
24
 
25
  @dataclass
@@ -749,96 +749,49 @@ def clear():
749
  return "", 0.1, "", problem_1_display, problem_2_display, problem_1_full, problem_2_full
750
 
751
 
752
- css = """
753
- .top-margin {
754
- margin-top: 20px;
755
- }
756
-
757
- .problem-examples-container {
758
- display: flex;
759
- align-items: center;
760
- margin-bottom: 10px;
761
- border-radius: 8px;
762
- border: 1px solid rgb(229, 231, 235);
763
- padding: 24px 16px 10px 16px;
764
- position: relative;
765
- }
766
-
767
- .copy-button {
768
- flex: none;
769
- }
770
- .problem-container-label{
771
- position: absolute;
772
- top: 4px;
773
- left: 6px;
774
- color: rgb(107, 114, 128);
775
- }
776
- """
777
-
778
-
779
- with gr.Blocks(css=css) as demo:
780
- latex_delimiters = [
781
- {"left": "[", "right": "]", "display": True},
782
- ]
783
 
784
- problem_1_display, problem_2_display, problem_1_full, problem_2_full = update_problems()
 
 
785
 
786
- with gr.Row(elem_classes="problem-examples-container"):
787
- gr.Markdown(
788
- value="Problem example 1", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
789
- )
790
- problem_example_1 = gr.Markdown(value=problem_1_display, elem_classes="problem-text")
791
- copy_btn_1 = gr.Button("Copy", elem_classes="copy-button")
792
- with gr.Row(elem_classes="problem-examples-container"):
793
- gr.Markdown(
794
- value="Problem example 2", latex_delimiters=latex_delimiters, elem_classes="problem-container-label"
795
- )
796
- problem_example_2 = gr.Markdown(value=problem_2_display, elem_classes="problem-text")
797
- copy_btn_2 = gr.Button("Copy", elem_classes="copy-button")
798
-
799
- with gr.Row():
800
- inp = gr.Textbox(placeholder="Problem", label="Problem input", lines=5)
801
- with gr.Accordion("Advanced Options", open=False):
802
- temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
803
- with gr.Row():
804
- out = gr.Markdown(elem_classes=["top-margin"], latex_delimiters=latex_delimiters)
805
- with gr.Row():
806
- btn = gr.Button("Run")
807
- btn_clear = gr.Button("Clear")
808
-
809
- btn.click(fn=solve_problem, inputs=[inp, temperature], outputs=out)
810
-
811
- problem_1_full_hidden = gr.Markdown(value=problem_1_full, visible=False)
812
- problem_2_full_hidden = gr.Markdown(value=problem_2_full, visible=False)
813
-
814
- copy_btn_1.click(fn=copy_problem_to_input, inputs=[problem_1_full_hidden], outputs=[inp])
815
- copy_btn_2.click(fn=copy_problem_to_input, inputs=[problem_2_full_hidden], outputs=[inp])
816
-
817
- btn_clear.click(
818
- fn=clear,
819
- inputs=[],
820
- outputs=[
821
- inp,
822
- temperature,
823
- out,
824
- problem_example_1,
825
- problem_example_2,
826
- problem_1_full_hidden,
827
- problem_2_full_hidden,
828
- ],
829
- scroll_to_output=True,
830
- )
831
 
832
- demo.load(
833
- update_problems,
834
- inputs=None,
835
- outputs=[
836
- problem_example_1,
837
- problem_example_2,
838
- problem_1_full_hidden,
839
- problem_2_full_hidden,
840
- ],
841
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842
 
843
  if __name__ == "__main__":
844
  demo.queue(default_concurrency_limit=5).launch()
 
16
  from openai import OpenAI
17
 
18
 
19
+ # client = OpenAI(
20
+ # base_url=os.environ.get("SERVER_URL"),
21
+ # api_key=os.environ.get("HF_TOKEN"),
22
+ # )
23
 
24
 
25
  @dataclass
 
749
  return "", 0.1, "", problem_1_display, problem_2_display, problem_1_full, problem_2_full
750
 
751
 
752
+ with open("app.css", "r") as f:
753
+ css = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
 
755
+ latex_delimiters = [
756
+ {"left": "[", "right": "]", "display": True},
757
+ ]
758
 
759
+ with gr.Blocks(css=css, title="Math Olympiad Solver") as demo:
760
+ with gr.Row(elem_classes="title"):
761
+ gr.HTML("Math Olympiad Solver", elem_classes="title-content")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
 
763
+ with gr.Row(elem_classes="sub-title"):
764
+ gr.HTML("Here may need to add some description string", elem_classes="sub-title-content")
765
+
766
+ with gr.Row(elem_classes="main-area"):
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("Probelm example", elem_classes="probelm-example-title-content")
771
+
772
+ with gr.Blocks(elem_classes="action-container"):
773
+ gr.HTML("another", elem_classes="probelm-example-another")
774
+ gr.HTML("copy", elem_classes="probelm-example-copy")
775
+
776
+ with gr.Row(elem_classes="copy-icon-container"):
777
+ gr.Markdown(
778
+ value="Problem example 2",
779
+ latex_delimiters=latex_delimiters,
780
+ elem_classes="probelm-example-content",
781
+ )
782
+
783
+ with gr.Accordion("Advanced Options", open=False):
784
+ temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.1, label="Temperature")
785
+
786
+ inp = gr.Textbox(placeholder="Problem", label="Problem input", lines=5)
787
+
788
+ with gr.Row():
789
+ btn = 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(latex_delimiters=latex_delimiters)
795
 
796
  if __name__ == "__main__":
797
  demo.queue(default_concurrency_limit=5).launch()