KZTech's picture
Update app.py
8dcc7ce verified
raw
history blame
906 Bytes
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}")