Spaces:
Runtime error
Runtime error
debu das
commited on
Commit
·
70ac413
1
Parent(s):
159c7a3
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,30 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def ocr(image):
|
8 |
-
#
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
st.markdown(f'**OCR Output:**\n{text}')
|
13 |
|
14 |
# Set up the Streamlit app
|
15 |
-
st.title('Image OCR')
|
16 |
|
17 |
-
#
|
18 |
-
image = st.file_uploader('Choose an image')
|
19 |
|
20 |
-
#
|
21 |
if image is not None:
|
22 |
-
|
23 |
-
|
|
|
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}')
|