import streamlit as st from PIL import Image import pytesseract 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:") # Upload block uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"]) # Show uploaded image and extraction options if uploaded_file is not None: try: image = Image.open(uploaded_file) st.image(image, caption="Uploaded Image", use_column_width=True) if st.button("Extract Text"): with st.spinner("Extracting text..."): text = pytesseract.image_to_string(image) st.success("✅ Text extracted!") st.text_area("Extracted Text", value=text, height=300) except Exception as e: st.error(f"❌ Error: {e}")