image-to-text / app.py
KZTech's picture
Update app.py
9bed501 verified
raw
history blame
1.01 kB
import streamlit as st
from PIL import Image
import pytesseract
import io
# Set Tesseract binary path for Hugging Face
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
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 using Tesseract OCR.")
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
if uploaded_file:
try:
image = Image.open(io.BytesIO(uploaded_file.read()))
st.image(image, caption="Uploaded Image", use_column_width=True)
if st.button("Extract Text"):
with st.spinner("Extracting text..."):
extracted_text = pytesseract.image_to_string(image)
st.success("Text extracted!")
st.text_area("Extracted Text", extracted_text, height=300)
except Exception as e:
st.error(f"❌ Failed to process image: {e}")
else:
st.info("Please upload an image.")