debu das commited on
Commit
e66cbf8
1 Parent(s): 86b4c94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -1,27 +1,29 @@
 
 
1
  import streamlit as st
2
- import paddleocr
 
 
3
 
4
- # Set up the OCR model
5
- model = paddleocr.create_model(mode='rec', lang='ch_sim')
6
 
7
- def ocr_image(image):
8
- # Perform OCR on the image
9
- text = model.recognize(image)
 
 
 
 
 
 
10
 
11
- return text
12
 
13
- # Set up the Streamlit app
14
- st.title('OCR App')
15
-
16
- # Add a file upload widget
17
- uploaded_file = st.file_uploader('Choose an image file')
18
 
 
19
  if uploaded_file is not None:
20
- # Read the image file
21
- image = Image.open(uploaded_file)
22
-
23
- # Perform OCR on the image
24
- text = ocr_image(image)
25
-
26
- # Display the OCR results
27
- st.text(text)
 
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")
24
  if uploaded_file is not None:
25
+ # To read file as bytes:
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')