admin
commited on
Commit
·
75fe06e
1
Parent(s):
93baa3e
sync ms
Browse files- app.py +31 -15
- requirements.txt +1 -2
- solution.py +1 -1
app.py
CHANGED
@@ -3,15 +3,31 @@ import gradio as gr
|
|
3 |
from sympy.core.numbers import Rational
|
4 |
from solution import BadInput, solutions
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_md(args_dict, name):
|
8 |
try:
|
9 |
ans_latex = solutions[name](**args_dict).get_latex_ans()
|
10 |
|
11 |
except BadInput as e:
|
12 |
-
return f"
|
13 |
|
14 |
-
return f"
|
15 |
|
16 |
|
17 |
def float_to_fraction(x):
|
@@ -44,7 +60,7 @@ def float_to_fraction(x):
|
|
44 |
|
45 |
def infer_pi(p, q):
|
46 |
if q == 0:
|
47 |
-
return "
|
48 |
|
49 |
p, q = float_to_fraction(p / q)
|
50 |
args_dict = {"p": p, "q": q}
|
@@ -53,7 +69,7 @@ def infer_pi(p, q):
|
|
53 |
|
54 |
def infer_e(p, q):
|
55 |
if q == 0:
|
56 |
-
return "
|
57 |
|
58 |
p, q = float_to_fraction(p / q)
|
59 |
args_dict = {"p": p, "q": q}
|
@@ -62,7 +78,7 @@ def infer_e(p, q):
|
|
62 |
|
63 |
def infer_eq(q1, q2, u, v):
|
64 |
if q2 == 0 or v == 0:
|
65 |
-
return "
|
66 |
|
67 |
q1, q2 = float_to_fraction(q1 / q2)
|
68 |
u, v = float_to_fraction(u / v)
|
@@ -72,7 +88,7 @@ def infer_eq(q1, q2, u, v):
|
|
72 |
|
73 |
def infer_pin(n: int, p, q):
|
74 |
if q == 0:
|
75 |
-
return "
|
76 |
|
77 |
p, q = float_to_fraction(p / q)
|
78 |
args_dict = {"n": n, "p": p, "q": q}
|
@@ -88,7 +104,7 @@ if __name__ == "__main__":
|
|
88 |
__import__(f"solutions.{file_name[:-3]}")
|
89 |
|
90 |
with gr.Blocks() as demo:
|
91 |
-
gr.Markdown("#
|
92 |
with gr.Tabs():
|
93 |
with gr.TabItem("π"):
|
94 |
gr.Interface(
|
@@ -98,12 +114,12 @@ if __name__ == "__main__":
|
|
98 |
gr.Number(label="q", value=100),
|
99 |
],
|
100 |
outputs=gr.Markdown(
|
101 |
-
value="####
|
102 |
show_copy_button=True,
|
103 |
container=True,
|
104 |
min_height=122,
|
105 |
),
|
106 |
-
title="
|
107 |
flagging_mode="never",
|
108 |
)
|
109 |
|
@@ -115,12 +131,12 @@ if __name__ == "__main__":
|
|
115 |
gr.Number(label="q", value=1000),
|
116 |
],
|
117 |
outputs=gr.Markdown(
|
118 |
-
value="####
|
119 |
show_copy_button=True,
|
120 |
container=True,
|
121 |
min_height=122,
|
122 |
),
|
123 |
-
title="
|
124 |
flagging_mode="never",
|
125 |
)
|
126 |
|
@@ -134,12 +150,12 @@ if __name__ == "__main__":
|
|
134 |
gr.Number(label="v", value=1000),
|
135 |
],
|
136 |
outputs=gr.Markdown(
|
137 |
-
value="####
|
138 |
show_copy_button=True,
|
139 |
container=True,
|
140 |
min_height=122,
|
141 |
),
|
142 |
-
title="
|
143 |
flagging_mode="never",
|
144 |
)
|
145 |
|
@@ -152,12 +168,12 @@ if __name__ == "__main__":
|
|
152 |
gr.Number(label="q", value=1),
|
153 |
],
|
154 |
outputs=gr.Markdown(
|
155 |
-
value="####
|
156 |
show_copy_button=True,
|
157 |
container=True,
|
158 |
min_height=122,
|
159 |
),
|
160 |
-
title="
|
161 |
flagging_mode="never",
|
162 |
)
|
163 |
|
|
|
3 |
from sympy.core.numbers import Rational
|
4 |
from solution import BadInput, solutions
|
5 |
|
6 |
+
EN_US = os.getenv("LANG") != "zh_CN.UTF-8"
|
7 |
+
ZH2EN = {
|
8 |
+
"比较 π^n 与 p/q 大小": "Compare π^n and p/q",
|
9 |
+
"#### 证明结果": "#### Proof result",
|
10 |
+
"比较 e^(p/q) 与 u/v 大小": "Compare e^(p/q) and u/v",
|
11 |
+
"比较 e 与 p/q 大小": "Compare e and p/q",
|
12 |
+
"比较 π 与 p/q 大小": "Compare π and p/q",
|
13 |
+
"# “注意到”证明法比较大小": "# Compare sizes by 'Note that' proof",
|
14 |
+
"注意到": "Note that",
|
15 |
+
"证毕!": "QED",
|
16 |
+
}
|
17 |
+
|
18 |
+
|
19 |
+
def _L(zh_txt: str):
|
20 |
+
return ZH2EN[zh_txt] if EN_US else zh_txt
|
21 |
+
|
22 |
|
23 |
def generate_md(args_dict, name):
|
24 |
try:
|
25 |
ans_latex = solutions[name](**args_dict).get_latex_ans()
|
26 |
|
27 |
except BadInput as e:
|
28 |
+
return f"输入错误, 请输入有效的数字: {e}"
|
29 |
|
30 |
+
return f"{_L('注意到')} $${ans_latex}$$ {_L('证毕!')}"
|
31 |
|
32 |
|
33 |
def float_to_fraction(x):
|
|
|
60 |
|
61 |
def infer_pi(p, q):
|
62 |
if q == 0:
|
63 |
+
return "分母不能为 0 !"
|
64 |
|
65 |
p, q = float_to_fraction(p / q)
|
66 |
args_dict = {"p": p, "q": q}
|
|
|
69 |
|
70 |
def infer_e(p, q):
|
71 |
if q == 0:
|
72 |
+
return "分母不能为 0 !"
|
73 |
|
74 |
p, q = float_to_fraction(p / q)
|
75 |
args_dict = {"p": p, "q": q}
|
|
|
78 |
|
79 |
def infer_eq(q1, q2, u, v):
|
80 |
if q2 == 0 or v == 0:
|
81 |
+
return "分母不能为 0 !"
|
82 |
|
83 |
q1, q2 = float_to_fraction(q1 / q2)
|
84 |
u, v = float_to_fraction(u / v)
|
|
|
88 |
|
89 |
def infer_pin(n: int, p, q):
|
90 |
if q == 0:
|
91 |
+
return "分母不能为 0 !"
|
92 |
|
93 |
p, q = float_to_fraction(p / q)
|
94 |
args_dict = {"n": n, "p": p, "q": q}
|
|
|
104 |
__import__(f"solutions.{file_name[:-3]}")
|
105 |
|
106 |
with gr.Blocks() as demo:
|
107 |
+
gr.Markdown(_L("# “注意到”证明法比较大小"))
|
108 |
with gr.Tabs():
|
109 |
with gr.TabItem("π"):
|
110 |
gr.Interface(
|
|
|
114 |
gr.Number(label="q", value=100),
|
115 |
],
|
116 |
outputs=gr.Markdown(
|
117 |
+
value=_L("#### 证明结果"),
|
118 |
show_copy_button=True,
|
119 |
container=True,
|
120 |
min_height=122,
|
121 |
),
|
122 |
+
title=_L("比较 π 与 p/q 大小"),
|
123 |
flagging_mode="never",
|
124 |
)
|
125 |
|
|
|
131 |
gr.Number(label="q", value=1000),
|
132 |
],
|
133 |
outputs=gr.Markdown(
|
134 |
+
value=_L("#### 证明结果"),
|
135 |
show_copy_button=True,
|
136 |
container=True,
|
137 |
min_height=122,
|
138 |
),
|
139 |
+
title=_L("比较 e 与 p/q 大小"),
|
140 |
flagging_mode="never",
|
141 |
)
|
142 |
|
|
|
150 |
gr.Number(label="v", value=1000),
|
151 |
],
|
152 |
outputs=gr.Markdown(
|
153 |
+
value=_L("#### 证明结果"),
|
154 |
show_copy_button=True,
|
155 |
container=True,
|
156 |
min_height=122,
|
157 |
),
|
158 |
+
title=_L("比较 e^(p/q) 与 u/v 大小"),
|
159 |
flagging_mode="never",
|
160 |
)
|
161 |
|
|
|
168 |
gr.Number(label="q", value=1),
|
169 |
],
|
170 |
outputs=gr.Markdown(
|
171 |
+
value=_L("#### 证明结果"),
|
172 |
show_copy_button=True,
|
173 |
container=True,
|
174 |
min_height=122,
|
175 |
),
|
176 |
+
title=_L("比较 π^n 与 p/q 大小"),
|
177 |
flagging_mode="never",
|
178 |
)
|
179 |
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
sympy~=1.12
|
2 |
pywebview~=5.3.2
|
3 |
-
ttkbootstrap~=1.10.1
|
4 |
-
gradio
|
|
|
1 |
sympy~=1.12
|
2 |
pywebview~=5.3.2
|
3 |
+
ttkbootstrap~=1.10.1
|
|
solution.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from typing import Iterable, Callable
|
2 |
-
from sympy import Eq,
|
3 |
|
4 |
|
5 |
class CannotCalculate(Exception):
|
|
|
1 |
from typing import Iterable, Callable
|
2 |
+
from sympy import Eq, Expr, Symbol, linsolve, simplify, latex
|
3 |
|
4 |
|
5 |
class CannotCalculate(Exception):
|