File size: 1,981 Bytes
4087097
51e2a0f
de19363
49290fb
51e2a0f
78e41ea
 
 
 
 
 
51e2a0f
 
 
 
 
 
84c05a2
 
 
 
 
 
 
 
51e2a0f
de19363
2b3df54
de19363
 
51e2a0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de19363
 
 
 
51e2a0f
78e41ea
51e2a0f
de19363
51e2a0f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import pulp
import pandas as pd
import openpyxl

w_style="""
<style>
footer {visibility: hidden; }
</style>
"""

demo = gr.Blocks()

def fx1(x):
    return f"欢迎练习Gradio, {x}!"

def fx2(x,y):
    m=pulp.LpProblem()
    x=list(map(int,x.split(',')))
    t=[pulp.LpVariable('t'+str(i),cat=pulp.LpBinary) for i in range(len(x))]
    m+=pulp.lpDot(x,t)
    m+=(pulp.lpDot(x,t)==y)
    m.solve()
    resu={'data':[x[i] for i in range(len(t)) if pulp.value(t[i])]}
    return resu

def fx3(x):
    df=pd.read_excel(x,header=0,engine='openpyxl')
    return df
    
with demo:
    gr.Markdown(
    """
    # WEB APP测试应用!
    ![执一以为天下式](https://pbihub.cn/uploads/images/201809/23/44/n6xk1x6UnN.gif#pic_center).
    """)
    with gr.Tabs():
        with gr.TabItem("测试1"):
            text_input = gr.Textbox(placeholder='请输入测试字符串,如"畅心"',label="请输入测试内容",show_label=True)
            text_output = gr.Textbox(label="输出结果",show_label=True)
            tj_button = gr.Button("提交>>")
        with gr.TabItem("凑数"):
            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)]
            json_output = gr.JSON(label="输出运算结果",show_label=True)
            cs_button = gr.Button("开始凑数>>")
        with gr.TabItem("文件交互"):
            file_input = gr.File(file_count="single",label="请选择需要读取的excel文件",show_label=True)
            table_output = gr.Dataframe(label="输出读取的表格数据",show_label=True)
            dq_button = gr.Button("开始读取>>")

    tj_button.click(fx1, inputs=text_input, outputs=text_output,css=w_style)
    cs_button.click(fx2, inputs=val_input, outputs=json_output)
    dq_button.click(fx3, inputs=file_input, outputs=table_output)

demo.launch()