changxin commited on
Commit
51e2a0f
·
1 Parent(s): 1888628

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -1,6 +1,12 @@
1
  import gradio as gr
2
- import json,pulp
3
- def fx(x,y):
 
 
 
 
 
 
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
- title = "测试WEB APP"
14
- description = """
15
- <center>
16
- 执一以为天下式!
17
- <img src="https://pbihub.cn/uploads/images/201809/23/44/n6xk1x6UnN.gif" width=380px>
18
- </center>
19
- """
20
- article = "加入[组团吹水](https://qm.qq.com/cgi-bin/qm/qr?k=ueJ_sPuOGHOlzSsUC5lVTBdKpQP-PXbO&jump_from=webapi),你不来我不老!"
21
-
22
- gr.Interface(fn=fx,inputs=[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)],outputs=gr.JSON(label="输出运算结果",show_label=True),title = title, description = description, article = article).launch()
 
 
 
 
 
 
 
 
 
 
 
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
+ ![执一以为天下式](https://pbihub.cn/uploads/images/201809/23/44/n6xk1x6UnN.gif#pic_center).
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()