Spaces:
Running
Running
Update chatgpt-ad-maker.py
Browse files- chatgpt-ad-maker.py +36 -41
chatgpt-ad-maker.py
CHANGED
@@ -1,57 +1,52 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
threshold (float): Brightness threshold for dot appearance
|
12 |
-
dot_color (list): RGB color of dots
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Convert input to grayscale
|
18 |
-
gray_image = np.mean(input_image, axis=2)
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
for y in range(0, height, dot_size):
|
28 |
-
for x in range(0, width, dot_size):
|
29 |
-
if normalized[y, x] > threshold:
|
30 |
-
radius = int(dot_size * normalized[y, x])
|
31 |
-
center_x, center_y = x + dot_size//2, y + dot_size//2
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
return
|
41 |
|
42 |
# Create Gradio interface
|
43 |
iface = gr.Interface(
|
44 |
-
fn=
|
45 |
inputs=[
|
46 |
-
gr.Image(
|
47 |
-
gr.Slider(minimum=
|
48 |
-
gr.Slider(minimum=0, maximum=
|
49 |
-
gr.ColorPicker(label="Dot Color", value="#FFFFFF")
|
50 |
],
|
51 |
-
outputs=gr.Image(
|
52 |
title="ChatGPT Ad Maker",
|
53 |
-
description="
|
54 |
)
|
55 |
|
56 |
-
|
57 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
+
import cv2
|
4 |
|
5 |
+
def create_dot_effect(image, dot_size=10, spacing=2):
|
6 |
+
# Convert to grayscale if image is color
|
7 |
+
if len(image.shape) == 3:
|
8 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
9 |
+
else:
|
10 |
+
gray = image
|
11 |
|
12 |
+
# Create a blank canvas
|
13 |
+
height, width = gray.shape
|
14 |
+
canvas = np.zeros_like(gray)
|
|
|
|
|
15 |
|
16 |
+
# Calculate number of dots based on spacing
|
17 |
+
y_dots = range(0, height, dot_size + spacing)
|
18 |
+
x_dots = range(0, width, dot_size + spacing)
|
|
|
|
|
19 |
|
20 |
+
# Create dots based on brightness
|
21 |
+
for y in y_dots:
|
22 |
+
for x in x_dots:
|
23 |
+
# Get the average brightness of the region
|
24 |
+
region = gray[y:min(y+dot_size, height), x:min(x+dot_size, width)]
|
25 |
+
if region.size > 0:
|
26 |
+
brightness = np.mean(region)
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Draw circle if the region is bright enough
|
29 |
+
if brightness > 30: # Threshold can be adjusted
|
30 |
+
cv2.circle(canvas,
|
31 |
+
(x + dot_size//2, y + dot_size//2),
|
32 |
+
dot_size//2,
|
33 |
+
(255),
|
34 |
+
-1)
|
35 |
|
36 |
+
return canvas
|
37 |
|
38 |
# Create Gradio interface
|
39 |
iface = gr.Interface(
|
40 |
+
fn=create_dot_effect,
|
41 |
inputs=[
|
42 |
+
gr.Image(label="Input Image"),
|
43 |
+
gr.Slider(minimum=2, maximum=20, value=10, step=1, label="Dot Size"),
|
44 |
+
gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Dot Spacing")
|
|
|
45 |
],
|
46 |
+
outputs=gr.Image(label="Dotted Image"),
|
47 |
title="ChatGPT Ad Maker",
|
48 |
+
description="Convert your image into a dotted pattern. Adjust dot size and spacing using the sliders."
|
49 |
)
|
50 |
|
51 |
+
if __name__ == "__main__":
|
52 |
+
iface.launch()
|