Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Function to convert image to sketch
|
7 |
+
def convert_to_sketch(image):
|
8 |
+
# Convert image to grayscale
|
9 |
+
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
10 |
+
|
11 |
+
# Invert the grayscale image
|
12 |
+
inverted_gray_image = 255 - gray_image
|
13 |
+
|
14 |
+
# Apply Gaussian Blur
|
15 |
+
blurred_image = cv2.GaussianBlur(inverted_gray_image, (21, 21), 0)
|
16 |
+
|
17 |
+
# Invert the blurred image
|
18 |
+
inverted_blurred_image = 255 - blurred_image
|
19 |
+
|
20 |
+
# Create the pencil sketch image
|
21 |
+
sketch_image = cv2.divide(gray_image, inverted_blurred_image, scale=256.0)
|
22 |
+
|
23 |
+
return sketch_image
|
24 |
+
|
25 |
+
# Streamlit app
|
26 |
+
st.title("ColorifyAI Sketch Generator")
|
27 |
+
st.write("Upload an image to convert it into a sketch!")
|
28 |
+
|
29 |
+
# Add the logo
|
30 |
+
logo_url = "https://huggingface.co/spaces/Felguk/ColorifyAI/resolve/main/unnamed.jpg"
|
31 |
+
st.image(logo_url, width=200) # Adjust the width as needed
|
32 |
+
|
33 |
+
# Upload image - allow all image formats
|
34 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"])
|
35 |
+
|
36 |
+
if uploaded_file is not None:
|
37 |
+
# Read the image
|
38 |
+
image = Image.open(uploaded_file)
|
39 |
+
image = np.array(image)
|
40 |
+
|
41 |
+
# Convert the image to sketch
|
42 |
+
sketch_image = convert_to_sketch(image)
|
43 |
+
|
44 |
+
# Display the original image
|
45 |
+
st.image(image, caption='Original Image', use_column_width=True)
|
46 |
+
|
47 |
+
# Display the sketch image
|
48 |
+
st.image(sketch_image, caption='Sketch Image', use_column_width=True)
|