Huhujingjing commited on
Commit
34a73d6
·
verified ·
1 Parent(s): a68a733

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -3
app.py CHANGED
@@ -1,7 +1,109 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
 
 
 
3
 
4
+ #!/usr/bin/env python
5
+ # coding: utf-8
6
+
7
+ import pandas as pd
8
+ import math
9
+
10
+
11
+
12
+ results = None
13
+ r_m = []
14
+ r_l1 = []
15
+ r_l2 = []
16
+ r_ls = []
17
+
18
+ if L2 == 0:
19
+ if LS == 0:
20
+ raise Exception('Error! L2 and LS cannot be both 0, please input again!')
21
+ else:
22
+ for m in range(math.ceil(2*A / M) + 1):
23
+ for l1 in range(math.ceil(2*A / L1) + 1):
24
+ for ls in range(math.ceil(2*A / LS) + 1):
25
+ total_mass = M * m + L1 * l1 + LS * ls
26
+ if (z * A - n <= total_mass <= z * A + n) and ls < m:
27
+ r_m.append(m)
28
+ r_l1.append(l1)
29
+ r_l2.append(None)
30
+ r_ls.append(ls)
31
+
32
+ results = {
33
+ 'M': r_m,
34
+ 'L1': r_l1,
35
+ 'L2': r_l2,
36
+ 'LS': r_ls,
37
+ }
38
+ df = pd.DataFrame(results)
39
+ print("符合 {} =< {}*m+{}*l1+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
40
+ .format(A - n, M, L1, LS, A + n, len(r_m)))
41
+
42
+ print(df.to_markdown(tablefmt="grid"))
43
+ df.to_csv("result.csv", index=False)
44
+
45
+ else:
46
+ if LS == 0:
47
+ for m in range(math.ceil(2*A / M) + 1):
48
+ for l1 in range(math.ceil(2*A / L1) + 1):
49
+ for l2 in range(math.ceil(2*A / L2) + 1):
50
+ total_mass = M * m + L1 * l1 + L2 * l2
51
+ if z * A - n <= total_mass <= z * A + n:
52
+ r_m.append(m)
53
+ r_l1.append(l1)
54
+ r_l2.append(l2)
55
+ r_ls.append(None)
56
+
57
+ results = {
58
+ 'M': r_m,
59
+ 'L1': r_l1,
60
+ 'L2': r_l2,
61
+ 'LS': r_ls,
62
+ }
63
+ df = pd.DataFrame(results)
64
+ print("符合 {} =< {}*m+{}*l1+{}*l2 <= {} 的所有自然数解有{}组,分别为:"
65
+ .format(A - n, M, L1, L2, A + n, len(r_m)))
66
+
67
+ print(df.to_markdown(tablefmt="grid"))
68
+ df.to_csv("result.csv", index=False)
69
+
70
+ else:
71
+ for m in range(math.ceil(2*A / M) + 1):
72
+ for l1 in range(math.ceil(2*A / L1) + 1):
73
+ for l2 in range(math.ceil(2*A / L2) + 1):
74
+ for ls in range(math.ceil(2*A / LS) + 1):
75
+ total_mass = M * m + L1 * l1 + L2 * l2 + LS * ls
76
+ if (z * A - n <= total_mass <= z * A + n) and ls < m:
77
+ r_m.append(m)
78
+ r_l1.append(l1)
79
+ r_l2.append(l2)
80
+ r_ls.append(ls)
81
+
82
+ results = {
83
+ 'M': r_m,
84
+ 'L1': r_l1,
85
+ 'L2': r_l2,
86
+ 'LS': r_ls,
87
+ }
88
+ df = pd.DataFrame(results)
89
+ print("符合 {} =< {}*m+{}*l1+{}*l2+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
90
+ .format(A - n, M, L1, L2, LS, A + n, len(r_m)))
91
+
92
+ print(df.to_markdown(tablefmt="grid"))
93
+ df.to_csv("result.csv", index=False)
94
+
95
+
96
+ def greet(M, L1, L2, LS, A, z, n):
97
+ return "# 输入参数:" + "-"*82 + "\n" + "|-M: 金属| -L1: 配体1 | -L2: 配体2 | -LS: 含S配体的相对分子质量 | -A: 质谱上对应的分子量 | -z: 电荷 |" + f"M:{M}\nL1:{L1}\nL2:{L2}\nLS:{LS}\nA:{A}\nz:{z}\nn:{n}"
98
+
99
+ iface = gr.Interface(fn=greet, inputs=[
100
+ gr.Textbox(lines=1),
101
+ gr.Textbox(lines=1),
102
+ gr.Textbox(lines=1),
103
+ gr.Textbox(lines=1),
104
+ gr.Textbox(lines=1),
105
+ gr.Textbox(lines=1),
106
+ gr.Textbox(lines=1)
107
+
108
+ ], outputs="text")
109
  iface.launch()