Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
m=pulp.LpProblem()
|
5 |
x=list(map(int,x.split(',')))
|
6 |
t=[pulp.LpVariable('t'+str(i),cat=pulp.LpBinary) for i in range(len(x))]
|
@@ -9,14 +15,24 @@ def fx(x,y):
|
|
9 |
m.solve()
|
10 |
resu={'data':[x[i] for i in range(len(t)) if pulp.value(t[i])]}
|
11 |
return resu
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import pulp
|
3 |
+
|
4 |
+
demo = gr.Blocks()
|
5 |
+
|
6 |
+
def fx1(x):
|
7 |
+
return f"欢迎练习Gradio, {x}!"
|
8 |
+
|
9 |
+
def fx2(x,y):
|
10 |
m=pulp.LpProblem()
|
11 |
x=list(map(int,x.split(',')))
|
12 |
t=[pulp.LpVariable('t'+str(i),cat=pulp.LpBinary) for i in range(len(x))]
|
|
|
15 |
m.solve()
|
16 |
resu={'data':[x[i] for i in range(len(t)) if pulp.value(t[i])]}
|
17 |
return resu
|
18 |
+
|
19 |
+
with demo:
|
20 |
+
gr.Markdown(
|
21 |
+
"""
|
22 |
+
# WEB APP测试应用!
|
23 |
+
.
|
24 |
+
""")
|
25 |
+
with gr.Tabs():
|
26 |
+
with gr.TabItem("测试1"):
|
27 |
+
text_input = gr.Textbox(placeholder='请输入测试字符串,如"畅心"',label="请输入测试内容",show_label=True)
|
28 |
+
text_output = gr.Textbox(label="输出结果",show_label=True)
|
29 |
+
tj_button = gr.Button("提交>>")
|
30 |
+
with gr.TabItem("凑数"):
|
31 |
+
val_input = [gr.Textbox(placeholder='请输入凑数序列,如"1,3,5,10,16,54,32,48,6,7"',label="请输入待凑数序列",show_label=True),gr.Number(value=80,label="请输入凑数和值",show_label=True)]
|
32 |
+
json_output = gr.JSON(label="输出运算结果",show_label=True)
|
33 |
+
cs_button = gr.Button("开始凑数>>")
|
34 |
+
|
35 |
+
tj_button.click(fx1, inputs=text_input, outputs=text_output)
|
36 |
+
cs_button.click(fx2, inputs=val_input, outputs=json_output)
|
37 |
+
|
38 |
+
demo.launch()
|