Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,26 @@
|
|
1 |
import streamlit as st
|
2 |
import easyocr
|
3 |
-
from PIL import Image
|
4 |
-
import numpy as np
|
5 |
import io
|
|
|
6 |
|
7 |
-
# Initialize the EasyOCR
|
8 |
reader = easyocr.Reader(['en'])
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
15 |
|
16 |
if uploaded_file:
|
17 |
-
#
|
18 |
-
image = Image.open(uploaded_file)
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
# Run OCR
|
25 |
-
result = reader.readtext(image_np)
|
26 |
-
|
27 |
-
# Display OCR results
|
28 |
-
st.subheader("OCR Results:")
|
29 |
-
for detection in result:
|
30 |
-
text = detection[1]
|
31 |
-
bbox = detection[0]
|
32 |
-
st.write(f"Text: {text}")
|
33 |
-
st.write(f"Bounding Box: {bbox}")
|
|
|
1 |
import streamlit as st
|
2 |
import easyocr
|
|
|
|
|
3 |
import io
|
4 |
+
from PIL import Image
|
5 |
|
6 |
+
# Initialize the EasyOCR reader
|
7 |
reader = easyocr.Reader(['en'])
|
8 |
|
9 |
+
# Function to extract text from image
|
10 |
+
def extract_text_from_image(image):
|
11 |
+
result = reader.readtext(image)
|
12 |
+
extracted_text = "\n".join([text[1] for text in result])
|
13 |
+
return extracted_text
|
14 |
|
15 |
+
# Streamlit interface
|
16 |
+
st.title("OCR Text Extraction with EasyOCR")
|
17 |
+
uploaded_file = st.file_uploader("Upload an image (JPG, PNG, etc.)", type=["jpg", "png"])
|
18 |
|
19 |
if uploaded_file:
|
20 |
+
# Read the image file
|
21 |
+
image = Image.open(uploaded_file)
|
22 |
+
# Extract text from the image
|
23 |
+
extracted_text = extract_text_from_image(image)
|
24 |
+
|
25 |
+
st.subheader("Extracted Text:")
|
26 |
+
st.write(extracted_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|