Spaces:
Running
Running
Update chatgpt-ad-maker.py
Browse files- chatgpt-ad-maker.py +61 -11
chatgpt-ad-maker.py
CHANGED
@@ -35,18 +35,68 @@ def create_dot_effect(image, dot_size=10, spacing=2):
|
|
35 |
|
36 |
return canvas
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Create Gradio interface
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
gr.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
iface.launch()
|
|
|
35 |
|
36 |
return canvas
|
37 |
|
38 |
+
def process_video(video_path, dot_size=10, spacing=2):
|
39 |
+
# Read the video
|
40 |
+
cap = cv2.VideoCapture(video_path)
|
41 |
+
if not cap.isOpened():
|
42 |
+
return None
|
43 |
+
|
44 |
+
# Get video properties
|
45 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
46 |
+
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
47 |
+
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
48 |
+
|
49 |
+
# Create temporary output file with mp4v codec
|
50 |
+
output_path = "temp_output.mp4"
|
51 |
+
fourcc = cv2.VideoWriter_fourcc(*'avc1') # Changed from 'mp4v' to 'avc1' (h264 codec)
|
52 |
+
out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height), False)
|
53 |
+
|
54 |
+
while cap.isOpened():
|
55 |
+
ret, frame = cap.read()
|
56 |
+
if not ret:
|
57 |
+
break
|
58 |
+
|
59 |
+
# Convert BGR to RGB for processing
|
60 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
61 |
+
# Apply dot effect
|
62 |
+
dotted_frame = create_dot_effect(frame_rgb, dot_size, spacing)
|
63 |
+
out.write(dotted_frame)
|
64 |
+
|
65 |
+
cap.release()
|
66 |
+
out.release()
|
67 |
+
|
68 |
+
return output_path
|
69 |
+
|
70 |
# Create Gradio interface
|
71 |
+
with gr.Blocks(title="ChatGPT Ad Maker") as iface:
|
72 |
+
gr.Markdown("# ChatGPT Ad Maker")
|
73 |
+
gr.Markdown("Convert your image or video into a dotted pattern. Adjust dot size and spacing using the sliders.")
|
74 |
+
|
75 |
+
with gr.Tab("Image"):
|
76 |
+
image_input = gr.Image(label="Input Image")
|
77 |
+
with gr.Row():
|
78 |
+
img_dot_size = gr.Slider(minimum=2, maximum=20, value=10, step=1, label="Dot Size")
|
79 |
+
img_spacing = gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Dot Spacing")
|
80 |
+
image_output = gr.Image(label="Dotted Output")
|
81 |
+
image_button = gr.Button("Process Image")
|
82 |
+
image_button.click(
|
83 |
+
fn=create_dot_effect,
|
84 |
+
inputs=[image_input, img_dot_size, img_spacing],
|
85 |
+
outputs=image_output
|
86 |
+
)
|
87 |
+
|
88 |
+
with gr.Tab("Video"):
|
89 |
+
video_input = gr.Video(label="Input Video")
|
90 |
+
with gr.Row():
|
91 |
+
vid_dot_size = gr.Slider(minimum=2, maximum=20, value=10, step=1, label="Dot Size")
|
92 |
+
vid_spacing = gr.Slider(minimum=0, maximum=10, value=2, step=1, label="Dot Spacing")
|
93 |
+
video_output = gr.Video(label="Dotted Output", format="mp4")
|
94 |
+
video_button = gr.Button("Process Video")
|
95 |
+
video_button.click(
|
96 |
+
fn=process_video,
|
97 |
+
inputs=[video_input, vid_dot_size, vid_spacing],
|
98 |
+
outputs=video_output
|
99 |
+
)
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
iface.launch()
|