Paddle_OCR / app.py
debu das
Update app.py
47219a9
raw
history blame
1.52 kB
import os
import streamlit as st
import paddlehub as hub
from PIL import Image
import io
from paddleocr import PaddleOCR,draw_ocr
def ocr(img,lang):
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang=lang) # need to run only once to download and load model into memory
img_path = 'PaddleOCR/doc/imgs_en/img_12.jpg'
result = ocr.ocr(img, cls=True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
# draw result
from PIL import Image
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
st.text(boxes)
txts = [line[1][0] for line in result]
st.text(txts)
scores = [line[1][1] for line in result]
st.text(scores)
#im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
#im_show = Image.fromarray(im_show)
#st.image(im_show, caption='Sunrise by the mountains')
#im_show.save('result.jpg')
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# To read file as bytes:
bytes_data = uploaded_file.getvalue()
st.write(bytes_data)
image = Image.open(io.BytesIO(bytes_data))
st.image(image, caption='Sunrise by the mountains')
ocr(image,'ch')