import streamlit as st from PIL import Image import pytesseract import io def perform_ocr(image): try: text = pytesseract.image_to_string(image) return text except Exception as e: return f"An error occurred: {str(e)}" def main(): st.title("Image to Text Converter") st.write("Upload an image and get the extracted text!") uploaded_file = st.file_uploader("Choose an image...", 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) st.write("") st.write("Extracting text...") text = perform_ocr(image) st.write("Extracted Text:") st.write(text) if __name__ == "__main__": main()