Spaces:
Running
Running
import streamlit as st | |
import cv2 | |
import numpy as np | |
from PIL import Image | |
# Function to convert image to sketch | |
def convert_to_sketch(image): | |
# Convert image to grayscale | |
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
# Invert the grayscale image | |
inverted_gray_image = 255 - gray_image | |
# Apply Gaussian Blur | |
blurred_image = cv2.GaussianBlur(inverted_gray_image, (21, 21), 0) | |
# Invert the blurred image | |
inverted_blurred_image = 255 - blurred_image | |
# Create the pencil sketch image | |
sketch_image = cv2.divide(gray_image, inverted_blurred_image, scale=256.0) | |
return sketch_image | |
# Streamlit app | |
st.title("ColorifyAI Sketch Generator") | |
st.write("Upload an image to convert it into a sketch!") | |
# Add the logo | |
logo_url = "https://huggingface.co/spaces/Felguk/ColorifyAI/resolve/main/unnamed.jpg" | |
st.image(logo_url, width=200) # Adjust the width as needed | |
# Upload image - allow all image formats | |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"]) | |
if uploaded_file is not None: | |
# Read the image | |
image = Image.open(uploaded_file) | |
image = np.array(image) | |
# Convert the image to sketch | |
sketch_image = convert_to_sketch(image) | |
# Display the original image | |
st.image(image, caption='Original Image', use_column_width=True) | |
# Display the sketch image | |
st.image(sketch_image, caption='Sketch Image', use_column_width=True) |