File size: 1,501 Bytes
03d5541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)