debu das commited on
Commit
47219a9
1 Parent(s): e66cbf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -1,23 +1,37 @@
1
- import tempfile
2
  import os
3
  import streamlit as st
4
  import paddlehub as hub
5
  from PIL import Image
6
  import io
7
 
8
- pp_ocrv3 = hub.Module(name="ch_pp-ocrv3")
9
 
10
- def inference(img):
11
- with tempfile.TemporaryDirectory() as tempdir_name:
12
- pp_ocrv3.recognize_text(paths=[img],use_gpu=False,output_dir=tempdir_name,visualization=True)
13
- result_names = os.listdir(tempdir_name)
14
- output_image = Image.open(os.path.join(tempdir_name, result_names[0]))
15
- return [output_image]
16
-
17
- title="ch_PP-OCRv3"
18
- description="ch_PP-OCRv3 is a practical ultra-lightweight OCR system developed by PaddleOCR."
 
 
 
19
 
20
- examples=[['test.png']]
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23
  uploaded_file = st.file_uploader("Choose a file")
@@ -26,4 +40,5 @@ if uploaded_file is not None:
26
  bytes_data = uploaded_file.getvalue()
27
  st.write(bytes_data)
28
  image = Image.open(io.BytesIO(bytes_data))
29
- st.image(image, caption='Sunrise by the mountains')
 
 
 
1
  import os
2
  import streamlit as st
3
  import paddlehub as hub
4
  from PIL import Image
5
  import io
6
 
 
7
 
8
+ from paddleocr import PaddleOCR,draw_ocr
9
+ def ocr(img,lang):
10
+ # Paddleocr supports Chinese, English, French, German, Korean and Japanese.
11
+ # You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan`
12
+ # to switch the language model in order.
13
+ ocr = PaddleOCR(use_angle_cls=True, lang=lang) # need to run only once to download and load model into memory
14
+ img_path = 'PaddleOCR/doc/imgs_en/img_12.jpg'
15
+ result = ocr.ocr(img, cls=True)
16
+ for idx in range(len(result)):
17
+ res = result[idx]
18
+ for line in res:
19
+ print(line)
20
 
21
+ # draw result
22
+ from PIL import Image
23
+ result = result[0]
24
+ image = Image.open(img_path).convert('RGB')
25
+ boxes = [line[0] for line in result]
26
+ st.text(boxes)
27
+ txts = [line[1][0] for line in result]
28
+ st.text(txts)
29
+ scores = [line[1][1] for line in result]
30
+ st.text(scores)
31
+ #im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
32
+ #im_show = Image.fromarray(im_show)
33
+ #st.image(im_show, caption='Sunrise by the mountains')
34
+ #im_show.save('result.jpg')
35
 
36
 
37
  uploaded_file = st.file_uploader("Choose a file")
 
40
  bytes_data = uploaded_file.getvalue()
41
  st.write(bytes_data)
42
  image = Image.open(io.BytesIO(bytes_data))
43
+ st.image(image, caption='Sunrise by the mountains')
44
+ ocr(image,'ch')