import streamlit as st from PIL import Image import pytesseract import io # Optional: Specify the path to Tesseract OCR executable for Windows # Uncomment the line below and provide the correct path if you're on Windows # pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' # Apply custom CSS to improve the UI def apply_custom_css(): st.markdown(""" """, unsafe_allow_html=True) # Function to detect text in the image using Tesseract OCR def detect_text_in_image(image): # Convert image to grayscale (needed for OCR) gray_image = image.convert('L') # L mode is grayscale # Use pytesseract to extract text text = pytesseract.image_to_string(gray_image) return text.strip() # Main Application def main(): apply_custom_css() # Title and Description st.title("📸 Meme Master (No Text Images Only!)") st.markdown( "Upload an image **without any text** to create a custom meme!" ) # Image Upload uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) if uploaded_image: # Open the uploaded image image = Image.open(uploaded_image) # Check if the image contains text text_in_image = detect_text_in_image(image) if text_in_image: st.error("❌ This image contains text! Please upload an image without any text.") else: # Show the uploaded image st.image(image, caption="Uploaded Image", use_container_width=True) # Show success message and proceed with functionality st.success("✅ This image has no text. You can now proceed with the meme creation!") # Here, you can add more functionality (like meme creation, editing, etc.) else: # Message when no image is uploaded st.info("👆 Upload an image to start creating your meme.") # Run the app if __name__ == "__main__": main()