File size: 2,621 Bytes
feca544
 
2d0e5bd
feca544
 
 
 
 
 
 
74b0b86
feca544
 
 
 
 
 
 
 
6ce6d58
feca544
 
 
 
6ce6d58
feca544
3300787
2d0e5bd
07040a2
 
6ce6d58
 
07040a2
6ce6d58
 
 
 
 
2d0e5bd
 
 
fa2c390
2d0e5bd
 
 
 
 
 
 
 
 
6ce6d58
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
import cv2
import numpy as np
from PIL import Image
Image.MAX_IMAGE_PIXELS = None
import gradio as gr
        
def freemium_watermark(img, sb_logo):
    width_px, height_px = img.size
    # Convert the logo to "RGBA" mode and resize it to 80% of the image width
    sb_logo = sb_logo.convert("RGBA")
    new_logo_width = int(width_px * 0.7)  # 80% of the image width
    logo_ratio = new_logo_width / sb_logo.width
    new_logo_height = int(sb_logo.height * logo_ratio)
    sb_logo = sb_logo.resize((new_logo_width, new_logo_height))
    # Make the logo semi-translucent
    transparent_img = Image.new('RGBA', (sb_logo.width, sb_logo.height), (0, 0, 0, 0))  # Create a transparent image of the same size
    sb_logo = Image.blend(transparent_img, sb_logo, alpha=0.3)  # Blend the logo with the transparent image
    # Calculate the position to paste the logo at the center of the image
    paste_x_position = (width_px - new_logo_width) // 2
    paste_y_position = int(height_px * 0.4) - (new_logo_height // 2)
    img.paste(sb_logo, (paste_x_position, paste_y_position), sb_logo)
    # Save the image
    return img

    
sb_logo = Image.open("./SB_logo_horizontal.png")
with gr.Blocks(analytics_enabled=False, theme=gr.themes.Soft()) as demo:
    with gr.Row():
        with gr.Column():
            input = gr.Image(type="pil", label="Upload Image", sources=["upload"])
            gr.ClearButton(components=input)
            gr.Examples(examples=["hotel.jpg", "road_small.jpg", "preview_small.jpg", "trailer.jpg"], inputs=input)
        with gr.Column():
            output = gr.Image(type = "filepath", label="Sketch Drawing", show_share_button=False)
            gr.Markdown("<p style='text-align: center; font-size: 20px;'>Want to remove the watermark?</p>\n")
            gr.Markdown("<p style='text-align: center; font-size: 20px;'>Subscribe or <a href='https://skyebrowse.com/pricing'>purchase a model</a> starting at $3.<p>")
    
    @gr.on(inputs=[input], outputs=[output], show_progress="minimal")
    def sketch(input_path):   
        if input_path is None:
            return None
        img_array = np.array(input_path)
        # Line processing
        blurred = cv2.GaussianBlur(img_array, (7, 7), 0)
        edges = cv2.Canny(blurred, 100, 180)
        structuring_element = cv2.getStructuringElement(cv2.MORPH_RECT, (4,3))
        dilated_edges = cv2.dilate(edges, structuring_element, iterations=1)
        line_drawing = 255 - dilated_edges
        line_img = Image.fromarray(line_drawing)
        return freemium_watermark(line_img, sb_logo)

demo.queue(default_concurrency_limit=10).launch()