Spaces:
Build error
Build error
File size: 8,090 Bytes
4087097 51e2a0f de19363 49290fb 92b7644 30634dc 7a8cd80 3d82ba6 7b64e11 51e2a0f 78e41ea b1b51b3 c90cba8 5632065 c90cba8 0e3f977 ab4d2f7 0e3f977 6679556 fd0633a 51e2a0f 84c05a2 51e2a0f de19363 2b3df54 de19363 92b7644 0d69bc5 92b7644 b1b51b3 7a8cd80 fcd97d5 7a8cd80 ef7b3a4 696b830 3d82ba6 bbf28a0 c90cba8 7b64e11 5476739 a34e9ad 5476739 51e2a0f 2344342 dcf2381 51e2a0f d9b02b2 51e2a0f de19363 bfa6d8f de19363 92b7644 0d69bc5 92b7644 b1b51b3 381696d 3d0a9a5 821464d 7a8cd80 2344342 8595e64 7a8cd80 3d82ba6 bbf28a0 123169c bbf28a0 123169c bbf28a0 7665ddb 5476739 d19c811 0091883 5476739 7b64e11 3c96b9a 7a7caa7 a0230cd 92b7644 b1b51b3 8595e64 6613067 efb29df 7b64e11 5476739 51e2a0f e84cb12 |
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 |
import gradio as gr
import pulp
import pandas as pd
import openpyxl
import requests
import os
os.system('pip install paddlepaddle')
os.system('pip install paddleocr')
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import torch
import re
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
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(css='''
#chedan {-webkit-transition-duration: 0.4s; transition-duration: 0.4s; border-radius: 40%}
#chedan:hover {background-color: #4CAF50; color: white;}
#chedan:active {background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px);}
''')
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 fx6(img, lang):
ocr = PaddleOCR(use_angle_cls=True, lang={'中文':'ch','英文':'en','法文':'fr','德文':'german','韩文':'korean','日文':'japan'}[lang],use_gpu=False)
img_path = img.name
result = ocr.ocr(img_path, cls=True)
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores,
font_path='simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
return 'result.jpg',list(zip(txts))
def fx7(x,y):
res=re.findall(r'{0}'.format(y),x)
return res
def fx8(x,y,z):
res=re.sub(r'{0}'.format(x),y,z)
return res
def plot(v, a):
g = 9.81
theta = a / 180 * 3.14
tmax = ((2 * v) * np.sin(theta)) / g
timemat = tmax * np.linspace(0, 1, 40)[:, None]
x = (v * timemat) * np.cos(theta)
y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
fig = plt.figure()
plt.scatter(x=x, y=y, marker=".")
plt.xlim(0, 100)
plt.ylim(0, 60)
return fig
def fx9(x):
pd.options.plotting.backend='matplotlib'
plt.close('all')
ax = x.plot(x='数据1',y='数据2',kind='bar',title='chinese word error!', color=["red","green","purple"])
ax.table(cellText=df.values,colLabels=df.columns,loc='bottom',colLoc='center')
return ax.get_figure()
with demo:
gr.Markdown(
"""
# <center> WEB APP测试应用!
<div align=center><img src="https://pbihub.cn/uploads/images/201809/23/44/n6xk1x6UnN.gif" width="405" height="405" /></div>
""")
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("提交>>",elem_id="chedan")
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("OCR识别"):
ocr_input=[gr.Image(type='file', label='请提供你需要识别的照片'),gr.Dropdown(choices=['中文','英文','法文','德文','韩文','日文'], type="value", default='中文', label='请选择需要识别的语言')]
ocr_output=[gr.Image(type='file', label='识别结果'),gr.Dataframe(label="识别信息",show_label=True)]
ocr_button = gr.Button("开始ocr识别")
with gr.TabItem("正则处理"):
with gr.Row():
with gr.Column():
gr.Markdown('<center> 正则匹配')
zz1_input = [gr.Textbox(placeholder='请输入测试字符串,如"畅心语文100,数学666,英语95.7"',label="请输入测试内容"),gr.Textbox(placeholder='请输入正则表达式,如"\d+"',label="请输入正则表达式")]
zz1_output = gr.Dataframe(label="输出正则匹配数据",show_label=True)
zz1_button = gr.Button("开始正则处理>>")
with gr.Column():
gr.Markdown('<center> 正则替换')
zz2_input = [gr.Textbox(placeholder='输入正则表达式,如"\d+"',label="输入正则表达式"),gr.Textbox(placeholder='正则匹配对象替换为啥',label="输入替换为的字符串"),gr.Textbox(placeholder='待替换对象',label="输入原始字符串")]
zz2_output = gr.Textbox(label="输出",show_label=True)
zz2_button = gr.Button("开始正则替换>>")
with gr.TabItem("图表展示1"):
with gr.Row():
with gr.Group():
speed = gr.Slider(1, 30, 25, label="Speed")
angle = gr.Slider(0, 90, 45, label="Angle")
output = gr.Plot()
tb_button = gr.Button("Run")
with gr.Box():
pd_input=gr.Dataframe(headers=['数据1','数据2'],value=[[42,10],[68,15]],datatype='number',label="可编辑数据框",interactive=True)
pd_output=gr.Plot()
pd_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,api_name="df")
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
pva_button.click(fx5, inputs=[],outputs=pva_output)
ocr_button.click(fx6,inputs=ocr_input,outputs=ocr_output,api_name="ocr")
zz1_button.click(fx7,inputs=zz1_input,outputs=zz1_output,api_name="zzpp")
zz2_button.click(fx8,inputs=zz2_input,outputs=zz2_output,api_name="zzth")
tb_button.click(plot, [speed, angle], output)
pd_button.click(fx9,pd_input,pd_output)
demo.launch(enable_queue=True)
|