Spaces:
Running
Running
Update chatgpt-ad-maker.py
Browse files- chatgpt-ad-maker.py +15 -9
chatgpt-ad-maker.py
CHANGED
@@ -1,13 +1,15 @@
|
|
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
|
8 |
|
9 |
Args:
|
10 |
input_image (ndarray): Input image
|
|
|
|
|
|
|
11 |
|
12 |
Returns:
|
13 |
ndarray: Image with dotted effect
|
@@ -19,13 +21,12 @@ def dot_effect(input_image):
|
|
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] >
|
29 |
radius = int(dot_size * normalized[y, x])
|
30 |
center_x, center_y = x + dot_size//2, y + dot_size//2
|
31 |
|
@@ -34,18 +35,23 @@ def dot_effect(input_image):
|
|
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] =
|
38 |
|
39 |
return dot_mask
|
40 |
|
41 |
# Create Gradio interface
|
42 |
iface = gr.Interface(
|
43 |
fn=dot_effect,
|
44 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
|
4 |
+
def dot_effect(input_image, dot_size, threshold, dot_color):
|
5 |
"""
|
6 |
+
Convert input image to customizable dotted effect
|
7 |
|
8 |
Args:
|
9 |
input_image (ndarray): Input image
|
10 |
+
dot_size (int): Size of dots
|
11 |
+
threshold (float): Brightness threshold for dot appearance
|
12 |
+
dot_color (list): RGB color of dots
|
13 |
|
14 |
Returns:
|
15 |
ndarray: Image with dotted effect
|
|
|
21 |
normalized = (gray_image - gray_image.min()) / (gray_image.max() - gray_image.min())
|
22 |
|
23 |
# Create dot mask
|
|
|
24 |
height, width = gray_image.shape
|
25 |
dot_mask = np.zeros((height, width, 3), dtype=np.uint8)
|
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 |
|
|
|
35 |
if dx*dx + dy*dy <= radius*radius:
|
36 |
px, py = center_x + dx, center_y + dy
|
37 |
if 0 <= px < width and 0 <= py < height:
|
38 |
+
dot_mask[py, px] = dot_color
|
39 |
|
40 |
return dot_mask
|
41 |
|
42 |
# Create Gradio interface
|
43 |
iface = gr.Interface(
|
44 |
fn=dot_effect,
|
45 |
+
inputs=[
|
46 |
+
gr.Image(type="numpy", label="Input Image"),
|
47 |
+
gr.Slider(minimum=1, maximum=20, value=5, label="Dot Size"),
|
48 |
+
gr.Slider(minimum=0, maximum=1, value=0.3, label="Dot Threshold"),
|
49 |
+
gr.ColorPicker(label="Dot Color", value="#FFFFFF")
|
50 |
+
],
|
51 |
outputs=gr.Image(type="numpy"),
|
52 |
title="ChatGPT Ad Maker",
|
53 |
+
description="Transform images into customizable dotted effect"
|
54 |
)
|
55 |
|
56 |
# Launch the app
|
57 |
+
iface.launch()
|