File size: 906 Bytes
5a49c3d
 
 
8dcc7ce
5a49c3d
8dcc7ce
4c46b65
5a49c3d
8dcc7ce
5a49c3d
8dcc7ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a49c3d
4c46b65
95abc88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import streamlit as st
from PIL import Image
import pytesseract
import io

st.set_page_config(page_title="OCR - Image to Text", layout="centered")
st.title("🖼️ OCR - Image to Text")

st.write("Upload an image to extract text:")

uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])

if uploaded_file is not None:
    try:
        # Convert uploaded image to bytes and open with PIL
        image = Image.open(uploaded_file)

        # Show image preview
        st.image(image, caption="Preview", use_column_width=True)

        if st.button("Extract Text"):
            with st.spinner("Extracting text..."):
                text = pytesseract.image_to_string(image)
            st.success("Text extracted successfully!")
            st.text_area("Extracted Text", text, height=300)

    except Exception as e:
        st.error(f"⚠️ Failed to process the image: {e}")