Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,12 @@ import pulp
|
|
3 |
import pandas as pd
|
4 |
import openpyxl
|
5 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
w_style="""
|
8 |
<style>
|
@@ -44,6 +50,20 @@ def fx4(x):
|
|
44 |
def fx5():
|
45 |
return html_code
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
def fx7(input_path,input_path2):
|
49 |
input_img = load_img(input_path)
|
@@ -85,6 +105,10 @@ with demo:
|
|
85 |
qy_input=[gr.Image(label="待转换图片",type="filepath"),gr.Image(label="风格图片",type="filepath")]
|
86 |
qy_output=gr.Image(type="auto", label="输出")
|
87 |
qy_button = gr.Button("开始迁移>>")
|
|
|
|
|
|
|
|
|
88 |
|
89 |
tj_button.click(fx1, inputs=text_input, outputs=text_output)
|
90 |
cs_button.click(fx2, inputs=val_input, outputs=json_output,api_name="ghqj")
|
@@ -92,5 +116,6 @@ with demo:
|
|
92 |
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
|
93 |
pva_button.click(fx5, inputs=[],outputs=pva_output)
|
94 |
qy_button.click(fx7,inputs=qy_input,outputs=qy_output)
|
|
|
95 |
|
96 |
demo.launch()
|
|
|
3 |
import pandas as pd
|
4 |
import openpyxl
|
5 |
import requests
|
6 |
+
import os
|
7 |
+
os.system('pip install paddlepaddle')
|
8 |
+
os.system('pip install paddleocr')
|
9 |
+
from paddleocr import PaddleOCR, draw_ocr
|
10 |
+
from PIL import Image
|
11 |
+
import torch
|
12 |
|
13 |
w_style="""
|
14 |
<style>
|
|
|
50 |
def fx5():
|
51 |
return html_code
|
52 |
|
53 |
+
def fx6(img, lang):
|
54 |
+
ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
|
55 |
+
img_path = img.name
|
56 |
+
result = ocr.ocr(img_path, cls=True)
|
57 |
+
image = Image.open(img_path).convert('RGB')
|
58 |
+
boxes = [line[0] for line in result]
|
59 |
+
txts = [line[1][0] for line in result]
|
60 |
+
scores = [line[1][1] for line in result]
|
61 |
+
im_show = draw_ocr(image, boxes, txts, scores,
|
62 |
+
font_path='simfang.ttf')
|
63 |
+
im_show = Image.fromarray(im_show)
|
64 |
+
im_show.save('result.jpg')
|
65 |
+
return 'result.jpg'
|
66 |
+
|
67 |
|
68 |
def fx7(input_path,input_path2):
|
69 |
input_img = load_img(input_path)
|
|
|
105 |
qy_input=[gr.Image(label="待转换图片",type="filepath"),gr.Image(label="风格图片",type="filepath")]
|
106 |
qy_output=gr.Image(type="auto", label="输出")
|
107 |
qy_button = gr.Button("开始迁移>>")
|
108 |
+
with gr.TabItem("OCR识别"):
|
109 |
+
ocr_input=[gr.Image(type='file', label='请提供你需要识别的照片'),gr.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='ch', label='请选择需要识别的语言')]
|
110 |
+
ocr_output=gr.Image(type='file', label='识别结果')
|
111 |
+
ocr_button = gr.Button("开始ocr识别")
|
112 |
|
113 |
tj_button.click(fx1, inputs=text_input, outputs=text_output)
|
114 |
cs_button.click(fx2, inputs=val_input, outputs=json_output,api_name="ghqj")
|
|
|
116 |
tts_button.click(fx4, inputs=TS_input, outputs=audio_output)
|
117 |
pva_button.click(fx5, inputs=[],outputs=pva_output)
|
118 |
qy_button.click(fx7,inputs=qy_input,outputs=qy_output)
|
119 |
+
ocr_button.click(fx6,inputs=ocr_input,outputs=ocr_output,enable_queue=True)
|
120 |
|
121 |
demo.launch()
|