sarahai commited on
Commit
7ddd450
1 Parent(s): b93afe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -24
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 Reader
8
  reader = easyocr.Reader(['en'])
9
 
10
- # Streamlit interface
11
- st.title("OCR with EasyOCR")
 
 
 
12
 
13
- # Upload image
14
- uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
 
15
 
16
  if uploaded_file:
17
- # Open image file
18
- image = Image.open(uploaded_file).convert('RGB')
19
- st.image(image, caption='Uploaded Image', use_column_width=True)
20
-
21
- # Convert image to a format that EasyOCR can handle (numpy array)
22
- image_np = np.array(image)
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)