test / app.py
changxin's picture
Update app.py
b24edfb
raw
history blame
4.65 kB
import gradio as gr
import hashlib
import tempfile
import requests
import pandas as pd
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(s:str):
a=exec(s)
return {k: v for k, v in locals().items() if isinstance(v,pd.DataFrame)}
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
demo=gr.Blocks()
with demo:
with gr.Tabs():
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="输入文本",default="你好吗?我很好。")
TTS_button=gr.Button("合成")
TTS_button.click(inference, inputs=TTS_input, outputs=gr.Audio(label="输出合成结果"),api_name='tts')
with gr.TabItem("M-Formatter"):
gr.Markdown("# PowerQuery M语言脚本格式化测试")
M_input=gr.Textbox(label="请填写需要格式化的M脚本",default="let a=1,b=2 in a+b",lines=18)
M_output=gr.Textbox(label="格式化结果",lines=50)
M_button=gr.Button("开始格式化>>")
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表达式",default="扯淡=CALCULATE(VALUES('价格表'[单价]),FILTER('价格表','价格表'[产品]='销售表'[产品]))",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脚本测试")
d_input=gr.Textbox(label="请填写需要datatable库处理的脚本",lines=18)
d_output=gr.JSON(label="输出>")
d_button=gr.Button("开始编译>>")
d_button.click(fx_datatable, inputs=d_input, outputs=d_output,api_name='datatable')
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')
demo.launch()