Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,33 +2,32 @@ import gradio as gr
|
|
2 |
from PIL import Image
|
3 |
import io
|
4 |
|
5 |
-
def create_gif(
|
6 |
-
|
7 |
-
|
8 |
-
composite = editor_output["composite"]
|
9 |
-
|
10 |
-
# Use the composite image for GIF creation
|
11 |
-
img = composite.convert('RGBA')
|
12 |
|
13 |
frames = []
|
14 |
duration = 100 # Duration for each frame in milliseconds
|
15 |
total_frames = 18 # Total number of frames
|
16 |
|
17 |
-
size =
|
|
|
|
|
|
|
18 |
full_width = size[0]
|
19 |
step = full_width // (total_frames // 2)
|
20 |
|
21 |
# Create sliding transition
|
22 |
for i in range(0, full_width, step):
|
23 |
frame = Image.new('RGBA', size)
|
24 |
-
frame.paste(
|
25 |
-
frame.paste(
|
26 |
frames.append(frame.convert('P', palette=Image.ADAPTIVE))
|
27 |
|
28 |
for i in range(full_width, 0, -step):
|
29 |
frame = Image.new('RGBA', size)
|
30 |
-
frame.paste(
|
31 |
-
frame.paste(
|
32 |
frames.append(frame.convert('P', palette=Image.ADAPTIVE))
|
33 |
|
34 |
# Save as GIF
|
@@ -45,26 +44,41 @@ def create_gif(editor_output):
|
|
45 |
|
46 |
# Gradio interface
|
47 |
with gr.Blocks() as iface:
|
48 |
-
gr.Markdown("# Advanced GIF Generator with Image Editing")
|
49 |
|
50 |
with gr.Row():
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
generate_button.click(
|
66 |
create_gif,
|
67 |
-
inputs=[
|
68 |
outputs=[output_gif]
|
69 |
)
|
70 |
|
|
|
2 |
from PIL import Image
|
3 |
import io
|
4 |
|
5 |
+
def create_gif(editor1_output, editor2_output):
|
6 |
+
img1 = editor1_output["composite"].convert('RGBA')
|
7 |
+
img2 = editor2_output["composite"].convert('RGBA')
|
|
|
|
|
|
|
|
|
8 |
|
9 |
frames = []
|
10 |
duration = 100 # Duration for each frame in milliseconds
|
11 |
total_frames = 18 # Total number of frames
|
12 |
|
13 |
+
size = (256, 256) # Fixed size for both images
|
14 |
+
img1 = img1.resize(size, Image.LANCZOS)
|
15 |
+
img2 = img2.resize(size, Image.LANCZOS)
|
16 |
+
|
17 |
full_width = size[0]
|
18 |
step = full_width // (total_frames // 2)
|
19 |
|
20 |
# Create sliding transition
|
21 |
for i in range(0, full_width, step):
|
22 |
frame = Image.new('RGBA', size)
|
23 |
+
frame.paste(img1, (0, 0))
|
24 |
+
frame.paste(img2.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img2.crop((0, 0, i, size[1])))
|
25 |
frames.append(frame.convert('P', palette=Image.ADAPTIVE))
|
26 |
|
27 |
for i in range(full_width, 0, -step):
|
28 |
frame = Image.new('RGBA', size)
|
29 |
+
frame.paste(img2, (0, 0))
|
30 |
+
frame.paste(img1.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img1.crop((0, 0, i, size[1])))
|
31 |
frames.append(frame.convert('P', palette=Image.ADAPTIVE))
|
32 |
|
33 |
# Save as GIF
|
|
|
44 |
|
45 |
# Gradio interface
|
46 |
with gr.Blocks() as iface:
|
47 |
+
gr.Markdown("# Advanced GIF Generator with Dual Image Editing")
|
48 |
|
49 |
with gr.Row():
|
50 |
+
with gr.Column(scale=2):
|
51 |
+
image_editor1 = gr.ImageEditor(
|
52 |
+
label="Edit Image 1",
|
53 |
+
brush=gr.Brush(colors=["#ff0000", "#00ff00", "#0000ff"]),
|
54 |
+
eraser=gr.Eraser(default_size=10),
|
55 |
+
height=300,
|
56 |
+
width="100%",
|
57 |
+
crop_size="1:1",
|
58 |
+
layers=True,
|
59 |
+
type="pil"
|
60 |
+
)
|
61 |
+
with gr.Column(scale=2):
|
62 |
+
image_editor2 = gr.ImageEditor(
|
63 |
+
label="Edit Image 2",
|
64 |
+
brush=gr.Brush(colors=["#ff0000", "#00ff00", "#0000ff"]),
|
65 |
+
eraser=gr.Eraser(default_size=10),
|
66 |
+
height=300,
|
67 |
+
width="100%",
|
68 |
+
crop_size="1:1",
|
69 |
+
layers=True,
|
70 |
+
type="pil"
|
71 |
+
)
|
72 |
|
73 |
+
with gr.Row():
|
74 |
+
generate_button = gr.Button("Generate GIF")
|
75 |
+
|
76 |
+
with gr.Row():
|
77 |
+
output_gif = gr.Image(type="filepath", label="Generated GIF", height=300)
|
78 |
|
79 |
generate_button.click(
|
80 |
create_gif,
|
81 |
+
inputs=[image_editor1, image_editor2],
|
82 |
outputs=[output_gif]
|
83 |
)
|
84 |
|