File size: 10,257 Bytes
3b87861
0c63622
68322e2
676f81f
a06ba85
b802901
 
d9561b9
676f81f
 
 
1e14657
 
676f81f
3b87861
c451602
 
 
1e14657
 
 
 
 
 
 
 
 
 
 
 
 
676f81f
4cad25d
630c584
 
4cad25d
630c584
8a8ce66
 
157537f
 
 
 
 
 
 
0c3cdf9
157537f
9b1c0bb
dfcaf77
 
 
 
770a12f
cea3760
a930236
 
dc56619
6519cb5
90b51a9
bb92751
 
 
 
 
ce9f2c6
 
 
 
 
 
 
 
bb92751
ce9f2c6
 
 
 
 
 
 
bb92751
ce9f2c6
bb92751
 
b802901
 
 
 
 
dc56619
676f81f
b24edfb
98cf4b9
b24edfb
fb273d7
445ff53
71955cc
1e14657
180eaf9
da43c80
 
 
 
 
 
28e1c18
1926a35
322a014
f9be81d
04edcd6
bab8483
b276092
 
676f81f
f018e3b
4cad25d
 
 
 
 
 
 
 
fb872a3
4cad25d
b276092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26abf11
b276092
 
eae7302
4cad25d
 
fb872a3
4cad25d
3a46bcb
4cad25d
157537f
 
 
 
fb872a3
157537f
 
 
9b1c0bb
 
 
80a558f
 
 
 
3a46bcb
9b1c0bb
770a12f
28e1c18
 
cb2df2d
37b967a
fb6299c
7c82acb
816011b
83c2bf6
29fbf64
cb2df2d
816011b
83c2bf6
22e9a27
1465d91
6084274
 
 
 
 
cea3760
 
9fed53d
3386a2d
bb92751
 
 
2e4c9f7
 
2cb5bf3
 
 
 
 
 
d9217c2
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import gradio as gr
import pandas as pd
from datatable import (dt, f,fread, by, ifelse, update, sort,count, min, max, mean, sum, rowsum,rowmean,rowcount,shift,rbind,cbind,union)
import requests
import openpyxl
import docx
from docx import Document

'''
import hashlib
import tempfile
from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer

def fx(x:str):
    hash=hashlib.md5()
    hash.update(x.encode(encoding='utf-8'))
    return hash.hexdigest()
    
manager = ModelManager()
model_path, config_path, model_item = manager.download_model("tts_models/zh-CN/baker/tacotron2-DDC-GST")
synthesizer = Synthesizer(
    model_path, config_path, None, None, None,
)


def inference(text: str):
    wavs = synthesizer.tts(text)
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
        synthesizer.save_wav(wavs, fp)
        return fp.name
'''
def fx_m(s:str):
    headers= {"Content-Type": "application/json"}
    url="https://m-formatter.azurewebsites.net/api/v2"
    data={'code':s,'resultType':'text'}
    respose=requests.post(url,json=data,headers=headers)
    ms=respose.json()
    return ms['result']

def fx_dax(s:str):
    url="https://www.daxformatter.com/"
    data = {"embed":"1","l":"short","fx":s}
    ct=requests.post(url = url,data = data)
    html=ct.text
    s1=html.split('<div class="result">')[1]
    s2='<div class="result">'+s1.split('<a href')[0]+'<a href="https://pbihub.cn/users/44" target="_top"><img src="https://pbihub.cn/uploads/avatars/44_1536391253.jpg?imageView2/1/w/380/h/380" alt="万剑归宗" class="badge" width="380" height="380"></a>'
    return s2
    
def fx_datatable(code:str):
    namespace = {}
    fun = compile(code,'<string>','exec')
    exec(fun,namespace)
    return namespace['py_exe']
    
def xz():
    x=pd.DataFrame([{'姓名':'畅心','成绩':100},{'姓名':'吹水','成绩':66}])
    y=x.to_excel('statics/test.xlsx',index=False)
    return 'statics/test.xlsx'
def fx_rq(date:str):
    chinese_data_dict = {'1': '一','2': '二','3': '三','4': '四','5': '五','6': '六','7': '七','8': '八','9': '九','0': '〇'}
    chinese_data2_dict = {'一': '十','二': '二十','三': '三十'}
    for c in date:
        if c in chinese_data_dict:
            date = date.replace(c, chinese_data_dict[c])
    y = date.split('-')[0]
    m = date.split('-')[1]
    temp = ''
    if len(m) == 2:
        temp += chinese_data2_dict[m[0]]
        if m[1] != "〇":
            temp += m[1]
        m = temp

    d = date.split('-')[2]
    temp = ''
    if len(d) == 2:
        temp += chinese_data2_dict[d[0]]
        if d[1] != "〇":
            temp += d[1]
        d = temp

    date = y + '年' + m + '月' + d + '日'
    return date

def wd(x):
    doc=Document(x)
    all_paragraphs = document.paragraphs
    t=[y.text for paragraph in all_paragraphs]
    return t
    
'''    
def fx_dd(tk:str,s:str):
    headers= {"Content-Type": "application/json"}
    url="https://oapi.dingtalk.com/robot/send?access_token="+tk
    data={'msgtype':'text','text':{'title': '吹牛逼',"content": s}, 'at': {'atMobiles': [], 'isAtAll': True}}
    response=requests.post(url,json=data,headers=headers)
    return response.text    
        
def dd_ocr(tk,sl,dt):
    headers= {"Content-Type": "application/json"}
    url="https://oapi.dingtalk.com/topapi/ocr/structured/recognize?access_token="+tk
    dc={"身份证":"idcard","增值税发票":"invoice","营业执照":"blicense","银行卡":"bank_card","车牌":"car_no","机动车发票":"car_invoice","驾驶证":"driving_license","行驶证":"vehicle_license","火车票":"train_ticket","定额发票":"quota_invoice","出租车发票":"taxi_ticket","机票行程单":"air_itinerary","审批表单":"approval_table","花名册":"roster"}
    data={"image_url":sl,"type":dc[dt]}
    response=requests.post(url,json=data,headers=headers)
    return response.json()

def fx_dt(dc,x,y):
    DT=fread(dc)
    gr.JSON(DT.names)
    D_table=DT[:,sum(f[int(y-1)]),by(f[int(x-1)])]
    return D_table.to_pandas()
'''  

'''
        with gr.TabItem("测试1"):
            with gr.Column():
                text_input=gr.Textbox(placeholder='请输入测试字符串',label="请输入需要MD5加密的测试内容")
                text_output=gr.Textbox(label="输出",visible=False)
                text_input.change(fn=lambda visible: gr.update(visible=True), inputs=text_input, outputs=text_output)
                bb_button=gr.Button("运行")
                bb_button.click(fx, inputs=text_input, outputs=text_output,api_name='md5')
            with gr.Column():
                gr.Markdown("# TTS文本字符串转语音合成训练")
                TTS_input=gr.Textbox(label="输入文本") 
                TTS_button=gr.Button("合成")
                TTS_button.click(inference, inputs=TTS_input, outputs=gr.Audio(label="输出合成结果"),api_name='tts')          
        with gr.TabItem("钉钉群消息推送"):
            gr.Markdown("# 推送测试")
            dd_input=[gr.Textbox(label="请填写机器人token"),gr.Textbox(label="请填写需要推送的信息",lines=10)]
            dd_output=gr.Textbox(label="推送提示") 
            dd_button=gr.Button("提交")
            dd_button.click(fx_dd, inputs=dd_input, outputs=dd_output,api_name='dingding_robot')
            
        with gr.TabItem("钉钉ocr"):
            gr.Markdown("# 网络图片OCR识别")
            ocr_input=[gr.Textbox(label="请填写ocr_token"),gr.Textbox(label="请填写图片网址"),gr.Radio(["身份证","增值税发票","营业执照","银行卡","车牌","机动车发票","驾驶证","行驶证","火车票","定额发票","出租车发票","机票行程单","审批表单","花名册"],value="营业执照增值税发票",label="请选择识别类型:")]
            ocr_button=gr.Button("开始识别>>")
            ocr_output=gr.JSON(label="识别结果") 
            ocr_button.click(dd_ocr, inputs=ocr_input, outputs=ocr_output,api_name='dingding_ocr')
            
        with gr.TabItem("datatable"):
            gr.Markdown("# datatable测试")
            dt_input=[gr.File(label="选择需要读取的文档",type='bytes'),gr.Number(label='请输入分组列序号'),gr.Number(label='请输入聚合列序号')]
            dt_output=gr.DataFrame(label="输出",max_rows=10,wrap=True) 
            dt_button=gr.Button("分类汇总")
            dt_button.click(fx_dt, inputs=dt_input, outputs=dt_output,api_name='datatable')
'''  
    
demo=gr.Blocks(css="#jsc:hover{background-color: red;}")
with demo:
    with gr.Tabs():                
        with gr.TabItem("M-Formatter"):
            gr.Markdown("# PowerQuery M语言脚本格式化测试")
            M_input=gr.Textbox(label="请填写需要格式化的M脚本",lines=18)
            M_button=gr.Button("开始格式化>>")
            M_output=gr.Textbox(label="格式化结果",lines=50) 
            M_button.click(fx_m, inputs=M_input, outputs=M_output,api_name='M')
            
        with gr.TabItem("DAX-Formatter"):
            gr.Markdown("# DAX表达式格式化测试")
            with gr.Row():
                DAX_input=gr.Textbox(label="请填写需要格式化的DAX表达式",lines=28)
                DAX_button=gr.Button("格式化>>")
                DAX_output=gr.HTML(label="DAX表达式格式化结果") 
                DAX_button.click(fx_dax, inputs=DAX_input, outputs=DAX_output,api_name='DAX')

        with gr.TabItem("Python-Execute"):
            gr.Markdown("# Python脚本测试")
            test_code='''from datatable import (dt, f,fread, by, ifelse, update, sort,count, min, max, mean, sum, rowsum)
DT=fread('https://huggingface.co/spaces/changxin/test/raw/main/statics/test.csv')
d_t=DT[:,sum(f.销量),by('小组')]
py_exe=d_t.to_pandas()'''
            d_input=gr.Textbox(label="请填写需要datatable库处理的脚本(最终输出使用变量名py_exe)",lines=18,value=test_code)
            d_button=gr.Button("开始编译>>")
            d_output=gr.DataFrame(label="输出>",overflow_row_behaviour="paginate")
            d_button.click(fx_datatable, inputs=d_input, outputs=d_output,api_name='pyexe')
            
        with gr.TabItem("js"):
            gr.Markdown("# js处理测试")
            a=gr.Textbox(label='请输入需要js处理的字符串')
            js_output=gr.Textbox(label="JS输出") 
            js_button1=gr.Button("js_test")
            js_button2=gr.Button("js_test2")
            js_button=gr.Button("js逆序字符串处理")
            js_button3=gr.Button("调用js引用",elem_id="jsc")
            js_button1.click(None,a,js_output,_js="x=>'你好:'+x")
            js_button2.click(None,a,js_output,_js="x=>`你好:${x},欢迎吹水!`")
            js_button.click(None,a,js_output,_js="(x) => [...x].reverse().join('')",api_name='js')
            js_button3.click(None,a,js_output,_js='(x)=>md5(x);<script src="https://huggingface.co/spaces/changxin/test/raw/main/statics/md5.js"></script>')
            
        with gr.TabItem("画册展示"):
            gr.Markdown("# 画册展示_khc")
            S='<iframe style="height: 600px; width: 100%;" src="https://app.kuhuace.com/player/index.html?id=60" allowfullscreen="allowfullscreen"><iframe>'
            gr.HTML(S)
        with gr.TabItem("下载测试"):
            with gr.Row():
                xz_button=gr.Button("绑定下载资源>>")
                xz_button.click(xz,[], gr.File(label="输出下载资源"),api_name='xz')
        with gr.TabItem("date转换"):
            dt_input=gr.Textbox(label='请输入需要处理的日期字符串')
            dt_button=gr.Button("转换日期>>")
            dt_output=gr.Textbox(label='输出处理的日期字符串')
            dt_button.click(fx_rq,dt_input,dt_output,api_name='date_chinese')
            
        with gr.TabItem("读取word"):
            file_input = gr.File(file_count="single",label="请选择需要读取的word文件",show_label=True)
            text_output = gr.Textbox(label="输出读取文本",show_label=True)
            dq_button = gr.Button("开始读取>>") 
            dq_button.click(wd, inputs=file_input, outputs=text_output,api_name="word-text")
demo.launch()