Spaces:
Sleeping
Sleeping
| 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(""" | |
| <style> | |
| body { | |
| background-color: #f4f4f4; | |
| } | |
| .main { | |
| background-color: #ffffff; | |
| padding: 20px; | |
| border-radius: 10px; | |
| box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1); | |
| } | |
| .stButton > button { | |
| background-color: #007BFF; | |
| color: white; | |
| border-radius: 5px; | |
| padding: 10px 20px; | |
| } | |
| .stButton > button:hover { | |
| background-color: #0056b3; | |
| } | |
| .stSidebar { | |
| background-color: #f8f9fa; | |
| } | |
| </style> | |
| """, 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() | |