Spaces:
Runtime error
Runtime error
debu das
commited on
Commit
•
1f5596d
1
Parent(s):
70ac413
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
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('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
|
27 |
-
#
|
28 |
-
|
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)
|
|
|
|