Spaces:
Sleeping
Sleeping
import streamlit as st | |
from PIL import Image | |
import pytesseract | |
import os | |
# Use default Tesseract path in Hugging Face's OCR image | |
st.set_page_config(page_title="Image to Text OCR", layout="centered") | |
st.title("🖼️ Image to Text Converter (OCR)") | |
st.write("Upload an image and extract text using Optical Character Recognition (OCR).") | |
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"]) | |
if uploaded_file is not None: | |
image = Image.open(uploaded_file) | |
st.image(image, caption="Uploaded Image", use_column_width=True) | |
if st.button("Extract Text"): | |
with st.spinner("Extracting text..."): | |
try: | |
text = pytesseract.image_to_string(image) | |
st.subheader("Extracted Text") | |
st.text_area("Text Output", value=text, height=300) | |
except Exception as e: | |
st.error(f"Error: {e}") | |
else: | |
st.info("Please upload an image to get started.") | |