Spaces:
Sleeping
Sleeping
File size: 1,292 Bytes
55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 4d859b1 55c4146 |
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 33 34 35 36 37 38 39 |
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 (PNG, JPG, JPEG) to extract text.")
uploaded_file = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
image = None
if uploaded_file is not None:
# Display file metadata
st.write(f"**Filename:** {uploaded_file.name}")
st.write(f"**Type:** {uploaded_file.type}")
st.write(f"**Size:** {uploaded_file.size} bytes")
try:
# Read bytes and open with PIL
bytes_data = uploaded_file.getvalue()
image = Image.open(io.BytesIO(bytes_data))
st.image(image, caption="Preview", use_column_width=True)
except Exception as e:
st.error(f"β οΈ Failed to open image: {e}")
# Only show extract button if image was loaded successfully
if image is not None:
if st.button("Extract Text"):
with st.spinner("Running OCR..."):
try:
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"β OCR error: {e}")
|