Spaces:
Running
Running
Upload chatgpt-ad-maker.py
Browse files- chatgpt-ad-maker.py +51 -0
chatgpt-ad-maker.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def dot_effect(input_image):
|
| 6 |
+
"""
|
| 7 |
+
Convert input image to dotted effect similar to the example
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
input_image (ndarray): Input image
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
ndarray: Image with dotted effect
|
| 14 |
+
"""
|
| 15 |
+
# Convert input to grayscale
|
| 16 |
+
gray_image = np.mean(input_image, axis=2)
|
| 17 |
+
|
| 18 |
+
# Normalize pixel values
|
| 19 |
+
normalized = (gray_image - gray_image.min()) / (gray_image.max() - gray_image.min())
|
| 20 |
+
|
| 21 |
+
# Create dot mask
|
| 22 |
+
dot_size = 5 # Adjust dot size as needed
|
| 23 |
+
height, width = gray_image.shape
|
| 24 |
+
dot_mask = np.zeros((height, width, 3), dtype=np.uint8)
|
| 25 |
+
|
| 26 |
+
for y in range(0, height, dot_size):
|
| 27 |
+
for x in range(0, width, dot_size):
|
| 28 |
+
if normalized[y, x] > 0.3: # Threshold for dot appearance
|
| 29 |
+
radius = int(dot_size * normalized[y, x])
|
| 30 |
+
center_x, center_y = x + dot_size//2, y + dot_size//2
|
| 31 |
+
|
| 32 |
+
for dy in range(-radius, radius):
|
| 33 |
+
for dx in range(-radius, radius):
|
| 34 |
+
if dx*dx + dy*dy <= radius*radius:
|
| 35 |
+
px, py = center_x + dx, center_y + dy
|
| 36 |
+
if 0 <= px < width and 0 <= py < height:
|
| 37 |
+
dot_mask[py, px] = [255, 255, 255]
|
| 38 |
+
|
| 39 |
+
return dot_mask
|
| 40 |
+
|
| 41 |
+
# Create Gradio interface
|
| 42 |
+
iface = gr.Interface(
|
| 43 |
+
fn=dot_effect,
|
| 44 |
+
inputs=gr.Image(type="numpy"),
|
| 45 |
+
outputs=gr.Image(type="numpy"),
|
| 46 |
+
title="ChatGPT Ad Maker",
|
| 47 |
+
description="Transform images into dotted effect"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Launch the app
|
| 51 |
+
iface.launch()
|