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