File size: 1,192 Bytes
d5da52b
 
 
613d9e4
d5da52b
dbaa8c5
613d9e4
 
187c644
d5da52b
 
 
 
 
 
 
 
 
 
 
 
 
613d9e4
 
 
 
 
 
d5da52b
 
ea1de69
187c644
613d9e4
dbaa8c5
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
import streamlit as st
from PIL import Image
import pytesseract
import os

# Explicitly set the Tesseract path for Hugging Face Spaces
if os.name == 'posix':  # Unix-like OS
    pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"

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 pytesseract.pytesseract.TesseractNotFoundError:
                st.error("Tesseract is not installed or not in the PATH. Please check your environment settings.")
else:
    st.info("Please upload an image to get started.")