File size: 980 Bytes
832f690
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 a PNG, JPG or JPEG image to extract text.")

uploaded_file = st.file_uploader("Choose an image file", type=["png", "jpg", "jpeg"])
if uploaded_file:
    try:
        # Read and open the image
        img_data = uploaded_file.read()
        image = Image.open(io.BytesIO(img_data))

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

        # Extraction button
        if st.button("Extract Text"):
            with st.spinner("Running OCR..."):
                text = pytesseract.image_to_string(image)
            st.subheader("Extracted Text")
            st.text_area("", text, height=300)

    except Exception as e:
        st.error(f"Failed to process image: {e}")
else:
    st.info("Please upload an image to get started.")