Spaces:
Build error
Build error
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=''' | |
<iframe width="800" height="800" frameborder="0" scrolling="no" src="https://dyrscomcn-my.sharepoint.com/personal/huangcaiguang_dyrs_com_cn/_layouts/15/Doc.aspx?sourcedoc={6d3da844-5b54-473b-a32a-08659600d015}&action=embedview&AllowTyping=True&ActiveCell='业绩'!A1&wdInConfigurator=True&wdInConfigurator=True&edesNext=false&ejss=false"></iframe> | |
''' | |
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 fx7(input_path,input_path2): | |
input_img = load_img(input_path) | |
input_img2 = load_img(input_path2) | |
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2') | |
stylized_image = hub_model(tf.constant(input_img), tf.constant(input_img2))[0] | |
pre_img = tensor_to_image(stylized_image) | |
return pre_img | |
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("Excel365测试"): | |
gr.HTML(value=ht_text,label="在线版演示",show_label=True) | |
with gr.TabItem("风格迁移"): | |
qy_input=[gr.Image(label="待转换图片",type="filepath"),gr.Image(label="风格图片",type="filepath")] | |
qy_output=gr.Image(type="auto", label="输出") | |
qy_button = gr.Button("开始迁移>>") | |
tj_button.click(fx1, inputs=text_input, outputs=text_output) | |
cs_button.click(fx2, inputs=val_input, outputs=json_output,api_name="ghqj") | |
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) | |
qy_button.click(fx7,inputs=qy_input,outputs=qy_output) | |
demo.launch() |