upload an image and extrat text
Drop files here
or click to upload
import streamlit as st
from PIL import Image
import pytesseract
import io
st.title("Image Text Extractor")
st.write("Upload an image and I'll extract any text I find in it!")
# File uploader
uploaded_file = st.file_uploader("Choose an image file", type=['png', 'jpg', 'jpeg'])
if uploaded_file is not None:
# Display the uploaded image
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
# Add a button to trigger text extraction
if st.button('Extract Text'):
try:
# Extract text from the image
st.write("Extracting text... Please wait...")
text = pytesseract.image_to_string(image)
if text.strip():
st.subheader("Extracted Text:")
st.write(text)
# Add download button for the extracted text
st.download_button(
label="Download extracted text",
data=text,
file_name="extracted_text.txt",
mime="text/plain"
)
else:
st.warning("No text was found in the image.")
except Exception as e:
st.error(f"An error occurred while extracting text: {str(e)}")
st.info("Make sure you have Tesseract installed on your system!")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?