Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,8 @@ def enhance_gif(images):
|
|
61 |
enhanced_images.append(np.array(img))
|
62 |
return enhanced_images
|
63 |
|
64 |
-
def create_gif_imageio(images,
|
|
|
65 |
gif_path = os.path.join(GENERATED_FILES_DIR, "output_enhanced.gif")
|
66 |
images_pil = [Image.fromarray(img) for img in images]
|
67 |
imageio.mimsave(gif_path, images_pil, duration=duration, loop=loop)
|
@@ -72,11 +73,11 @@ def process_image(image, grid_cols_input, grid_rows_input):
|
|
72 |
zip_file = zip_images(frames)
|
73 |
return zip_file
|
74 |
|
75 |
-
def process_image_to_gif(image, grid_cols_input, grid_rows_input):
|
76 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|
77 |
interpolated_frames = interpolate_frames(frames, factor=2)
|
78 |
enhanced_frames = enhance_gif(interpolated_frames)
|
79 |
-
gif_file = create_gif_imageio(enhanced_frames,
|
80 |
|
81 |
# Preview the first frame of the GIF
|
82 |
preview_image = Image.fromarray(enhanced_frames[0])
|
@@ -84,7 +85,7 @@ def process_image_to_gif(image, grid_cols_input, grid_rows_input):
|
|
84 |
preview_path = os.path.join(GENERATED_FILES_DIR, "preview_frame.png")
|
85 |
|
86 |
return preview_path, gif_file
|
87 |
-
|
88 |
def zip_images(images):
|
89 |
zip_path = os.path.join(GENERATED_FILES_DIR, "output.zip")
|
90 |
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
@@ -101,6 +102,7 @@ with gr.Blocks() as demo:
|
|
101 |
image_input = gr.Image(label="Input Image", type="pil")
|
102 |
grid_cols_input = gr.Slider(1, 10, value=2, step=1, label="Grid Columns")
|
103 |
grid_rows_input = gr.Slider(1, 10, value=2, step=1, label="Grid Rows")
|
|
|
104 |
with gr.Row():
|
105 |
zip_button = gr.Button("Create Zip File")
|
106 |
gif_button = gr.Button("Create GIF")
|
@@ -111,7 +113,7 @@ with gr.Blocks() as demo:
|
|
111 |
zip_button.click(process_image, inputs=[image_input, grid_cols_input, grid_rows_input], outputs=zip_output)
|
112 |
gif_button.click(
|
113 |
process_image_to_gif,
|
114 |
-
inputs=[image_input, grid_cols_input, grid_rows_input],
|
115 |
outputs=[preview_image, gif_output]
|
116 |
)
|
117 |
|
|
|
61 |
enhanced_images.append(np.array(img))
|
62 |
return enhanced_images
|
63 |
|
64 |
+
def create_gif_imageio(images, fps=10, loop=0):
|
65 |
+
duration = 1000 / fps # Convert FPS to milliseconds
|
66 |
gif_path = os.path.join(GENERATED_FILES_DIR, "output_enhanced.gif")
|
67 |
images_pil = [Image.fromarray(img) for img in images]
|
68 |
imageio.mimsave(gif_path, images_pil, duration=duration, loop=loop)
|
|
|
73 |
zip_file = zip_images(frames)
|
74 |
return zip_file
|
75 |
|
76 |
+
def process_image_to_gif(image, grid_cols_input, grid_rows_input, fps_input):
|
77 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|
78 |
interpolated_frames = interpolate_frames(frames, factor=2)
|
79 |
enhanced_frames = enhance_gif(interpolated_frames)
|
80 |
+
gif_file = create_gif_imageio(enhanced_frames, fps=fps_input, loop=0)
|
81 |
|
82 |
# Preview the first frame of the GIF
|
83 |
preview_image = Image.fromarray(enhanced_frames[0])
|
|
|
85 |
preview_path = os.path.join(GENERATED_FILES_DIR, "preview_frame.png")
|
86 |
|
87 |
return preview_path, gif_file
|
88 |
+
|
89 |
def zip_images(images):
|
90 |
zip_path = os.path.join(GENERATED_FILES_DIR, "output.zip")
|
91 |
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
|
|
102 |
image_input = gr.Image(label="Input Image", type="pil")
|
103 |
grid_cols_input = gr.Slider(1, 10, value=2, step=1, label="Grid Columns")
|
104 |
grid_rows_input = gr.Slider(1, 10, value=2, step=1, label="Grid Rows")
|
105 |
+
fps_input = gr.Slider(1, 30, value=10, step=1, label="FPS (Frames per Second)")
|
106 |
with gr.Row():
|
107 |
zip_button = gr.Button("Create Zip File")
|
108 |
gif_button = gr.Button("Create GIF")
|
|
|
113 |
zip_button.click(process_image, inputs=[image_input, grid_cols_input, grid_rows_input], outputs=zip_output)
|
114 |
gif_button.click(
|
115 |
process_image_to_gif,
|
116 |
+
inputs=[image_input, grid_cols_input, grid_rows_input, fps_input],
|
117 |
outputs=[preview_image, gif_output]
|
118 |
)
|
119 |
|