Spaces:
Runtime error
Runtime error
debu das
commited on
Commit
·
47219a9
1
Parent(s):
e66cbf8
Update app.py
Browse files
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 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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')
|