ChatGPT-ad-Maker / chatgpt-ad-maker.py
akhaliq's picture
akhaliq HF staff
Update chatgpt-ad-maker.py
678fc41 verified
raw
history blame
1.72 kB
import gradio as gr
import numpy as np
import cv2
def create_dot_effect(image, dot_size=10, spacing=2):
# Convert to grayscale if image is color
if len(image.shape) == 3:
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
else:
gray = image
# Create a blank canvas
height, width = gray.shape
canvas = np.zeros_like(gray)
# Calculate number of dots based on spacing
y_dots = range(0, height, dot_size + spacing)
x_dots = range(0, width, dot_size + spacing)
# Create dots based on brightness
for y in y_dots:
for x in x_dots:
# Get the average brightness of the region
region = gray[y:min(y+dot_size, height), x:min(x+dot_size, width)]
if region.size > 0:
brightness = np.mean(region)
# Draw circle if the region is bright enough
if brightness > 30: # Threshold can be adjusted
cv2.circle(canvas,
(x + dot_size//2, y + dot_size//2),
dot_size//2,
(255),
-1)
return canvas
# Create Gradio interface
iface = gr.Interface(
fn=create_dot_effect,
inputs=[
gr.Image(label="Input Image"),
gr.Slider(minimum=2, maximum=20, value=10, step=1, label="Dot Size"),
gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Dot Spacing")
],
outputs=gr.Image(label="Dotted Image"),
title="ChatGPT Ad Maker",
description="Convert your image into a dotted pattern. Adjust dot size and spacing using the sliders."
)
if __name__ == "__main__":
iface.launch()