Spaces:
Running
Running
udpate demo
Browse filesSigned-off-by: Zhang Jun <[email protected]>
- README.md +3 -25
- app.py +32 -52
- requirements.txt +3 -1
README.md
CHANGED
@@ -4,31 +4,9 @@ emoji: ⚡
|
|
4 |
colorFrom: pink
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
|
|
7 |
app_file: app.py
|
8 |
pinned: false
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
# Configuration
|
13 |
-
|
14 |
-
`title`: _string_
|
15 |
-
Display title for the Space
|
16 |
-
|
17 |
-
`emoji`: _string_
|
18 |
-
Space emoji (emoji-only character allowed)
|
19 |
-
|
20 |
-
`colorFrom`: _string_
|
21 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
22 |
-
|
23 |
-
`colorTo`: _string_
|
24 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
25 |
-
|
26 |
-
`sdk`: _string_
|
27 |
-
Can be either `gradio` or `streamlit`
|
28 |
-
|
29 |
-
`app_file`: _string_
|
30 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
31 |
-
Path is relative to the root of the repository.
|
32 |
-
|
33 |
-
`pinned`: _boolean_
|
34 |
-
Whether the Space stays on top of your list.
|
|
|
4 |
colorFrom: pink
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.23.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: Extract text from images in multiple languages
|
12 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,69 +1,49 @@
|
|
1 |
-
import os
|
2 |
-
os.system('pip install paddlepaddle')
|
3 |
-
os.system('pip install paddleocr')
|
4 |
-
import requests
|
5 |
from paddleocr import PaddleOCR, draw_ocr
|
6 |
from PIL import Image
|
7 |
import gradio as gr
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
-
def
|
12 |
-
|
13 |
-
Download an image from a specified URL and save it to the specified path
|
14 |
-
|
15 |
-
Args:
|
16 |
-
url (str): URL of the image
|
17 |
-
save_path (str): Path to save the image
|
18 |
-
|
19 |
-
Returns:
|
20 |
-
bool: True if download is successful, False otherwise
|
21 |
-
"""
|
22 |
-
try:
|
23 |
-
response = requests.get(url, stream=True)
|
24 |
-
if response.status_code == 200:
|
25 |
-
with open(save_path, 'wb') as file:
|
26 |
-
for chunk in response.iter_content(chunk_size=8192):
|
27 |
-
file.write(chunk)
|
28 |
-
print(f"Image successfully downloaded and saved as: {save_path}")
|
29 |
-
return True
|
30 |
-
else:
|
31 |
-
print(f"Download failed, status code: {response.status_code}")
|
32 |
-
return False
|
33 |
-
except Exception as e:
|
34 |
-
print(f"Error occurred during download: {str(e)}")
|
35 |
-
return False
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
def inference(img, lang):
|
42 |
-
|
43 |
-
img_path = img
|
44 |
-
result = ocr.ocr(img_path, cls=True)[0]
|
45 |
-
image = Image.open(img_path).convert('RGB')
|
46 |
-
boxes = [line[0] for line in result]
|
47 |
-
txts = [line[1][0] for line in result]
|
48 |
-
scores = [line[1][1] for line in result]
|
49 |
-
im_show = draw_ocr(image, boxes, txts, scores,
|
50 |
-
font_path='./simfang.ttf')
|
51 |
-
im_show = Image.fromarray(im_show)
|
52 |
-
im_show.save('result.jpg')
|
53 |
-
return 'result.jpg'
|
54 |
|
55 |
title = 'PaddleOCR'
|
56 |
-
description = '
|
57 |
-
|
58 |
-
examples
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
60 |
gr.Interface(
|
61 |
inference,
|
62 |
-
[
|
|
|
|
|
|
|
63 |
gr.Image(type='filepath', label='Output'),
|
64 |
title=title,
|
65 |
description=description,
|
66 |
-
article=article,
|
67 |
examples=examples,
|
68 |
css=css
|
69 |
-
).launch(debug=
|
|
|
|
|
|
|
|
|
|
|
1 |
from paddleocr import PaddleOCR, draw_ocr
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
4 |
|
5 |
+
lang_list = ['ch', 'en', 'fr', 'german', 'korean', 'japan']
|
6 |
+
ocr_dict = {lang: PaddleOCR(lang=lang, use_angle_cls=True, use_gpu=False) for lang in lang_list}
|
7 |
|
8 |
+
def inference(img, lang):
|
9 |
+
ocr = ocr_dict[lang]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
img_path = img
|
12 |
+
result = ocr.ocr(img_path, cls=True)[0]
|
13 |
+
image = Image.open(img_path).convert('RGB')
|
14 |
+
boxes = [line[0] for line in result]
|
15 |
+
txts = [line[1][0] for line in result]
|
16 |
+
scores = [line[1][1] for line in result]
|
17 |
+
im_show = draw_ocr(image, boxes, txts, scores,
|
18 |
+
font_path='./simfang.ttf')
|
19 |
+
im_show = Image.fromarray(im_show)
|
20 |
+
im_show.save('result.jpg')
|
21 |
+
return 'result.jpg'
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
title = 'PaddleOCR'
|
25 |
+
description = '''
|
26 |
+
- Gradio demo for PaddleOCR. PaddleOCR demo supports Chinese, English, French, German, Korean and Japanese.
|
27 |
+
- To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.
|
28 |
+
- [Docs](https://paddlepaddle.github.io/PaddleOCR/), [Github Repository](https://github.com/PaddlePaddle/PaddleOCR).
|
29 |
+
'''
|
30 |
+
|
31 |
+
examples = [
|
32 |
+
['en_example.jpg','en'],
|
33 |
+
['cn_example.jpg','ch'],
|
34 |
+
['jp_example.jpg','japan'],
|
35 |
+
]
|
36 |
+
|
37 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
38 |
gr.Interface(
|
39 |
inference,
|
40 |
+
[
|
41 |
+
gr.Image(type='filepath', label='Input'),
|
42 |
+
gr.Dropdown(choices=lang_list, value='en', label='language')
|
43 |
+
],
|
44 |
gr.Image(type='filepath', label='Output'),
|
45 |
title=title,
|
46 |
description=description,
|
|
|
47 |
examples=examples,
|
48 |
css=css
|
49 |
+
).launch(debug=False)
|
requirements.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
Pillow
|
2 |
Gradio
|
3 |
-
requests
|
|
|
|
|
|
1 |
Pillow
|
2 |
Gradio
|
3 |
+
requests
|
4 |
+
paddlepaddle
|
5 |
+
paddleocr
|