Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,91 @@ html_code='''
|
|
14 |
<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>
|
15 |
'''
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
demo = gr.Blocks()
|
18 |
|
19 |
def fx1(x):
|
@@ -40,6 +125,9 @@ def fx4(x):
|
|
40 |
def fx5():
|
41 |
return html_code
|
42 |
|
|
|
|
|
|
|
43 |
with demo:
|
44 |
gr.Markdown(
|
45 |
"""
|
@@ -66,11 +154,15 @@ with demo:
|
|
66 |
with gr.TabItem("Power Virtual Agents"):
|
67 |
pva_button = gr.Button("调用机器人对话>>")
|
68 |
pva_output=gr.HTML(label="机器人聊天窗口",show_label=True)
|
|
|
|
|
|
|
69 |
|
70 |
tj_button.click(fx1, inputs=text_input, outputs=text_output)
|
71 |
cs_button.click(fx2, inputs=val_input, outputs=json_output)
|
72 |
dq_button.click(fx3, inputs=file_input, outputs=table_output)
|
73 |
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
|
74 |
pva_button.click(fx5, inputs=[],outputs=pva_output)
|
|
|
75 |
|
76 |
demo.launch()
|
|
|
14 |
<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>
|
15 |
'''
|
16 |
|
17 |
+
ht_text='''
|
18 |
+
<head>
|
19 |
+
<title>吹牛逼</title>
|
20 |
+
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/pluginsCss.css" />
|
21 |
+
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/plugins.css" />
|
22 |
+
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/luckysheet.css" />
|
23 |
+
<link rel="stylesheet" href="https://powerquery.anvil.app/_/theme/iconfont.css" />
|
24 |
+
<script src="https://powerquery.anvil.app/_/theme/plugin.js"></script>
|
25 |
+
<script src="https://mengshukeji.github.io/LuckysheetDemo/luckysheet.umd.js"></script>
|
26 |
+
<script src="https://powerquery.anvil.app/_/theme/xlsx.full.min.js"></script>
|
27 |
+
<script>
|
28 |
+
$(function () {
|
29 |
+
var options = {
|
30 |
+
container: "pq",
|
31 |
+
functionButton: '<button id="download" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;" onclick="FX()">下载</button>',
|
32 |
+
title: "畅心测试",
|
33 |
+
lang: "zh",
|
34 |
+
userInfo: {userName:"畅心",userImage: "https://pbihub.cn/uploads/images/201809/12/44/LWNFWHW7Gj.png"},
|
35 |
+
data: [{"name":"sheet1","index":0,"status":1,"order":0,"color":"#ff0066","row":18,"column":12,"celldata":luckysheet.transToCellData([["维度表","度量值名称","表达式"],])}]
|
36 |
+
}
|
37 |
+
luckysheet.create(options)
|
38 |
+
});
|
39 |
+
|
40 |
+
function FX(){
|
41 |
+
var data = that.luckysheet.getAllSheets()[0].data;
|
42 |
+
var out = XLSX.utils.book_new(),aoa = [[]];
|
43 |
+
|
44 |
+
data.forEach(function(rows, index) {
|
45 |
+
aoa[index] = [];
|
46 |
+
for(var column = 0; column < rows.length - 1; column++) {
|
47 |
+
aoa[index][column] = rows[column] ? rows[column] : '';
|
48 |
+
}
|
49 |
+
});
|
50 |
+
|
51 |
+
var ws = XLSX.utils.aoa_to_sheet(aoa);
|
52 |
+
XLSX.utils.book_append_sheet(out, ws, 'sheet1');
|
53 |
+
|
54 |
+
XLSX.writeFile(out, 'sheet1.xlsx', {});
|
55 |
+
return true;
|
56 |
+
}
|
57 |
+
</script>
|
58 |
+
|
59 |
+
</head>
|
60 |
+
<body>
|
61 |
+
<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>
|
62 |
+
<p style="text-align:center;"> <input style="font-size:16px;" type="file" id="test" name="test" change="demoHandler" /></p>
|
63 |
+
<div id="pq" style="margin:0px;padding:0px;position:absolute;width:100%;left: 0px;top: 50px;bottom: 0px;outline: none;"></div>
|
64 |
+
<script src="https://powerquery.anvil.app/_/theme/luckyexcel.umd.js"></script>
|
65 |
+
<script>
|
66 |
+
function demoHandler(){
|
67 |
+
let upload = document.getElementById("test");
|
68 |
+
let mask = document.getElementById("md");
|
69 |
+
if(upload){
|
70 |
+
|
71 |
+
window.onload = () => {
|
72 |
+
upload.addEventListener("change", function(evt){
|
73 |
+
var files = evt.target.files;
|
74 |
+
if(files==null || files.length==0){alert("没有待加载文件!");return;}
|
75 |
+
|
76 |
+
let name = files[0].name;
|
77 |
+
let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length-1];
|
78 |
+
if(suffix!="xlsx"){alert("目前只支持xlsx文档导入!");return;}
|
79 |
+
LuckyExcel.transformExcelToLucky(files[0], function(exportJson, luckysheetfile){
|
80 |
+
|
81 |
+
if(exportJson.sheets==null || exportJson.sheets.length==0){alert("读取失败, 目前不支持xls文件!");return;}
|
82 |
+
console.log(exportJson, luckysheetfile);
|
83 |
+
window.luckysheet.destroy();
|
84 |
+
|
85 |
+
window.luckysheet.create({
|
86 |
+
container: 'pq',
|
87 |
+
showinfobar:false,
|
88 |
+
data:exportJson.sheets,
|
89 |
+
title:exportJson.info.name,
|
90 |
+
userInfo:exportJson.info.name.creator
|
91 |
+
});
|
92 |
+
});
|
93 |
+
});
|
94 |
+
}
|
95 |
+
}
|
96 |
+
}
|
97 |
+
demoHandler();
|
98 |
+
</script>
|
99 |
+
</body>
|
100 |
+
'''
|
101 |
+
|
102 |
demo = gr.Blocks()
|
103 |
|
104 |
def fx1(x):
|
|
|
125 |
def fx5():
|
126 |
return html_code
|
127 |
|
128 |
+
def fx6():
|
129 |
+
return ht_text
|
130 |
+
|
131 |
with demo:
|
132 |
gr.Markdown(
|
133 |
"""
|
|
|
154 |
with gr.TabItem("Power Virtual Agents"):
|
155 |
pva_button = gr.Button("调用机器人对话>>")
|
156 |
pva_output=gr.HTML(label="机器人聊天窗口",show_label=True)
|
157 |
+
with gr.TabItem("Luckysheet交互"):
|
158 |
+
lk_button = gr.Button("调用Luckysheet>>")
|
159 |
+
lk_output=gr.HTML(label="国产开源表格工具",show_label=True)
|
160 |
|
161 |
tj_button.click(fx1, inputs=text_input, outputs=text_output)
|
162 |
cs_button.click(fx2, inputs=val_input, outputs=json_output)
|
163 |
dq_button.click(fx3, inputs=file_input, outputs=table_output)
|
164 |
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
|
165 |
pva_button.click(fx5, inputs=[],outputs=pva_output)
|
166 |
+
lk_button.click(fx6, inputs=[],outputs=lk_output)
|
167 |
|
168 |
demo.launch()
|