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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,23 +1,30 @@
1
  import streamlit as st
2
- import paddleocr
3
 
4
- # Initialize the OCR engine
5
- engine = paddleocr.create_engine()
6
 
 
 
 
 
 
7
  def ocr(image):
8
- # Perform OCR on the image
9
- text = engine.run(image)
 
 
 
10
 
11
- # Display the OCR results
12
- st.markdown(f'**OCR Output:**\n{text}')
13
 
14
  # Set up the Streamlit app
15
- st.title('Image OCR')
16
 
17
- # Add a file uploader to the app
18
- image = st.file_uploader('Choose an image')
19
 
20
- # If an image is uploaded, display it and perform OCR on it
21
  if image is not None:
22
- st.image(image, caption='Input Image')
23
- ocr(image)
 
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}')