Spaces:
Sleeping
Sleeping
File size: 2,648 Bytes
0195eea a1d265a 0195eea 79d4da5 0195eea a1d265a 79d4da5 a1d265a 0195eea 79d4da5 a1d265a 0195eea a1d265a 0195eea a1d265a 0195eea a1d265a 0195eea a1d265a 0195eea 79d4da5 a1d265a 0195eea 79d4da5 0195eea a1d265a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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()
|