ColorifyAI / app.py
Felguk's picture
Update app.py
a2dd703 verified
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, blur_intensity, sketch_intensity):
# 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 with adjustable intensity
blurred_image = cv2.GaussianBlur(inverted_gray_image, (blur_intensity, blur_intensity), 0)
# Invert the blurred image
inverted_blurred_image = 255 - blurred_image
# Create the pencil sketch image with adjustable intensity
sketch_image = cv2.divide(gray_image, inverted_blurred_image, scale=sketch_intensity)
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"])
# Add settings in the sidebar
st.sidebar.title("Settings")
blur_intensity = st.sidebar.slider("Blur Intensity", min_value=1, max_value=99, value=21, step=2)
sketch_intensity = st.sidebar.slider("Sketch Intensity", min_value=100, max_value=300, value=256, step=10)
if uploaded_file is not None:
# Read the image
image = Image.open(uploaded_file)
image = np.array(image)
# Convert the image to sketch using the selected settings
sketch_image = convert_to_sketch(image, blur_intensity, sketch_intensity)
# 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)