import gradio as gr import numpy as np from PIL import Image def dot_effect(input_image): """ Convert input image to dotted effect similar to the example Args: input_image (ndarray): Input image Returns: ndarray: Image with dotted effect """ # Convert input to grayscale gray_image = np.mean(input_image, axis=2) # Normalize pixel values normalized = (gray_image - gray_image.min()) / (gray_image.max() - gray_image.min()) # Create dot mask dot_size = 5 # Adjust dot size as needed height, width = gray_image.shape dot_mask = np.zeros((height, width, 3), dtype=np.uint8) for y in range(0, height, dot_size): for x in range(0, width, dot_size): if normalized[y, x] > 0.3: # Threshold for dot appearance radius = int(dot_size * normalized[y, x]) center_x, center_y = x + dot_size//2, y + dot_size//2 for dy in range(-radius, radius): for dx in range(-radius, radius): if dx*dx + dy*dy <= radius*radius: px, py = center_x + dx, center_y + dy if 0 <= px < width and 0 <= py < height: dot_mask[py, px] = [255, 255, 255] return dot_mask # Create Gradio interface iface = gr.Interface( fn=dot_effect, inputs=gr.Image(type="numpy"), outputs=gr.Image(type="numpy"), title="ChatGPT Ad Maker", description="Transform images into dotted effect" ) # Launch the app iface.launch()