debu das commited on
Commit
1f5596d
1 Parent(s): 70ac413

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -1,30 +1,27 @@
1
  import streamlit as st
2
- import paddlehub as hub
3
 
4
- # Load the PaddleOCR module
5
- module = hub.Module(name='paddleocr')
6
 
7
- # Set the OCR detection language to English
8
- module.set_encode('utf-8')
9
- module.set_decode('utf-8')
10
-
11
- # Create a function to perform OCR on an image
12
- def ocr(image):
13
- # Use the PaddleOCR module to detect text in the image
14
- result = module.detection(images=[image])
15
-
16
- # Extract the text from the OCR result
17
- text = result[0]['data'][0]['text']
18
 
19
  return text
20
 
21
  # Set up the Streamlit app
22
- st.title('Image OCR with PaddleOCR')
 
 
 
 
 
 
 
23
 
24
- # Allow the user to upload an image
25
- image = st.file_uploader('Choose an image to OCR:')
26
 
27
- # Perform OCR on the image and display the result
28
- if image is not None:
29
- text = ocr(image)
30
- st.write(f'OCR result: {text}')
 
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)