Spaces:
Sleeping
Sleeping
import streamlit as st | |
from PIL import Image | |
import pytesseract | |
import shutil | |
# Streamlit app title | |
st.title("Image to Text Extraction App πΌοΈπ") | |
# Prompt for image upload | |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
# Check if tesseract is installed and in PATH | |
pytesseract.pytesseract.tesseract_cmd = shutil.which("tesseract") or None | |
# If an image is uploaded, perform OCR | |
if uploaded_file is not None: | |
image = Image.open(uploaded_file) | |
st.image(image, caption="Uploaded Image", use_column_width=True) | |
# Perform OCR using Tesseract | |
with st.spinner("Extracting text..."): | |
text = pytesseract.image_to_string(image) | |
# Display the extracted text | |
st.subheader("Extracted Text:") | |
st.write(text) | |
else: | |
st.warning("Please upload an image file to extract text.") | |