import gradio as gr import hashlib import tempfile import requests 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('
')[1] s2='
'+s1.split('>") 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') demo.launch()