Spaces:
Sleeping
Sleeping
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.") | |