File size: 860 Bytes
c75f8be | 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 | import gradio as gr
import cv2
import numpy as np
from PIL import Image
def image_to_sketch(image):
img = np.array(image.convert("RGB"))
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
inverted = 255 - gray
blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
def dodge(front, back):
return cv2.divide(front, 255 - back, scale=255)
sketch = dodge(gray, blurred)
return [image, Image.fromarray(sketch)]
# Create Gradio interface
demo = gr.Interface(
fn=image_to_sketch,
inputs=gr.Image(type="pil", label="Upload a portrait image"),
outputs=[
gr.Image(label="Original"),
gr.Image(label="Sketch"),
],
title="🖌️ Image to Sketch Converter",
description="Upload a portrait image and watch it turn into a pencil sketch!",
examples=None
)
if __name__ == "__main__":
demo.launch()
|