Spaces:
Build error
Build error
File size: 7,659 Bytes
4087097 51e2a0f de19363 49290fb 92b7644 51e2a0f 78e41ea b1b51b3 c90cba8 51e2a0f 84c05a2 51e2a0f de19363 2b3df54 de19363 92b7644 0d69bc5 92b7644 b1b51b3 c90cba8 51e2a0f de19363 92b7644 0d69bc5 92b7644 b1b51b3 381696d c90cba8 92b7644 3c96b9a 51e2a0f de19363 92b7644 b1b51b3 c90cba8 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import gradio as gr
import pulp
import pandas as pd
import openpyxl
import requests
w_style="""
<style>
footer {visibility: hidden; }
</style>
"""
html_code='''
<iframe src="https://web.powerva.microsoft.com/environments/Default-51a58d6c-4fcf-4b75-8608-d00bf7f244d5/bots/new_bot_830e155fc862429e89683426b31c9bd5/webchat" height="500" frameborder="1" style="width:100%"></iframe>
'''
ht_text='''
<head>
<title>吹牛逼</title>
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/pluginsCss.css" />
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/plugins.css" />
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/luckysheet.css" />
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/iconfont.css" />
<script src="https://powerquery.anvil.app/_/theme/plugin.js"></script>
<script src="https://mengshukeji.github.io/LuckysheetDemo/luckysheet.umd.js"></script>
<script src="https://powerquery.anvil.app/_/theme/xlsx.full.min.js"></script>
<script>
$(function () {
var options = {
container: "pq",
functionButton: '<button id="download" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;" onclick="FX()">下载</button>',
title: "畅心测试",
lang: "zh",
userInfo: {userName:"畅心",userImage: "https://pbihub.cn/uploads/images/201809/12/44/LWNFWHW7Gj.png"},
data: [{"name":"sheet1","index":0,"status":1,"order":0,"color":"#ff0066","row":18,"column":12,"celldata":luckysheet.transToCellData([["维度表","度量值名称","表达式"],])}]
}
luckysheet.create(options)
});
function FX(){
var data = that.luckysheet.getAllSheets()[0].data;
var out = XLSX.utils.book_new(),aoa = [[]];
data.forEach(function(rows, index) {
aoa[index] = [];
for(var column = 0; column < rows.length - 1; column++) {
aoa[index][column] = rows[column] ? rows[column] : '';
}
});
var ws = XLSX.utils.aoa_to_sheet(aoa);
XLSX.utils.book_append_sheet(out, ws, 'sheet1');
XLSX.writeFile(out, 'sheet1.xlsx', {});
return true;
}
</script>
</head>
<body>
<div id="md" style="position: absolute;z-index: 1000000;left: 0px;top: 0px;bottom: 0px;right: 0px; background: rgba(255, 255, 255, 0.8); text-align: center;font-size: 40px;align-items:center;justify-content: center;display: none;">Downloading</div>
<p style="text-align:center;"> <input style="font-size:16px;" type="file" id="test" name="test" change="demoHandler" /></p>
<div id="pq" style="margin:0px;padding:0px;position:absolute;width:100%;left: 0px;top: 50px;bottom: 0px;outline: none;"></div>
<script src="https://powerquery.anvil.app/_/theme/luckyexcel.umd.js"></script>
<script>
function demoHandler(){
let upload = document.getElementById("test");
let mask = document.getElementById("md");
if(upload){
window.onload = () => {
upload.addEventListener("change", function(evt){
var files = evt.target.files;
if(files==null || files.length==0){alert("没有待加载文件!");return;}
let name = files[0].name;
let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length-1];
if(suffix!="xlsx"){alert("目前只支持xlsx文档导入!");return;}
LuckyExcel.transformExcelToLucky(files[0], function(exportJson, luckysheetfile){
if(exportJson.sheets==null || exportJson.sheets.length==0){alert("读取失败, 目前不支持xls文件!");return;}
console.log(exportJson, luckysheetfile);
window.luckysheet.destroy();
window.luckysheet.create({
container: 'pq',
showinfobar:false,
data:exportJson.sheets,
title:exportJson.info.name,
userInfo:exportJson.info.name.creator
});
});
});
}
}
}
demoHandler();
</script>
</body>
'''
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
def fx4(x):
url_s="https://tts.baidu.com/text2audio?tex="+x+"&cuid=baike&lan=ZH&ie=utf-8&ctp=1&pdt=301&vol=9&rate=32&per=0"
return "点击音频文件 [voice]("+url_s+")"
def fx5():
return html_code
def fx6():
return ht_text
with demo:
gr.Markdown(
"""
# WEB APP测试应用!
.
""")
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("开始读取>>")
with gr.TabItem("TTS"):
TS_input = gr.Textbox(placeholder='请输入测试字符串,如"欢迎测试字符串转语音功能模块"',label="请输入测试内容",show_label=True)
audio_output = gr.Markdown(label="点击生成音频文件",show_label=True)
tts_button = gr.Button("开始转换>>")
with gr.TabItem("Power Virtual Agents"):
pva_button = gr.Button("调用机器人对话>>")
pva_output=gr.HTML(label="机器人聊天窗口",show_label=True)
with gr.TabItem("Luckysheet交互"):
lk_button = gr.Button("调用Luckysheet>>")
lk_output=gr.HTML(label="国产开源表格工具",show_label=True)
tj_button.click(fx1, inputs=text_input, outputs=text_output)
cs_button.click(fx2, inputs=val_input, outputs=json_output)
dq_button.click(fx3, inputs=file_input, outputs=table_output)
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
pva_button.click(fx5, inputs=[],outputs=pva_output)
lk_button.click(fx6, inputs=[],outputs=lk_output)
demo.launch() |