Update app.py
Browse files
app.py
CHANGED
@@ -66,7 +66,7 @@ def create_gif_imageio(images, duration=50, loop=0):
|
|
66 |
images_pil = [Image.fromarray(img) for img in images]
|
67 |
imageio.mimsave(gif_path, images_pil, duration=duration, loop=loop)
|
68 |
return gif_path
|
69 |
-
|
70 |
def process_image(image, grid_cols_input, grid_rows_input):
|
71 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|
72 |
zip_file = zip_images(frames)
|
@@ -77,7 +77,13 @@ def process_image_to_gif(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, duration=50, loop=0)
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
def zip_images(images):
|
83 |
zip_path = os.path.join(GENERATED_FILES_DIR, "output.zip")
|
@@ -99,9 +105,14 @@ with gr.Blocks() as demo:
|
|
99 |
zip_button = gr.Button("Create Zip File")
|
100 |
gif_button = gr.Button("Create GIF")
|
101 |
with gr.Row():
|
|
|
102 |
zip_output = gr.File(label="Download Zip File")
|
103 |
gif_output = gr.File(label="Download GIF")
|
104 |
zip_button.click(process_image, inputs=[image_input, grid_cols_input, grid_rows_input], outputs=zip_output)
|
105 |
-
gif_button.click(
|
|
|
|
|
|
|
|
|
106 |
|
107 |
demo.launch(show_error=True)
|
|
|
66 |
images_pil = [Image.fromarray(img) for img in images]
|
67 |
imageio.mimsave(gif_path, images_pil, duration=duration, loop=loop)
|
68 |
return gif_path
|
69 |
+
|
70 |
def process_image(image, grid_cols_input, grid_rows_input):
|
71 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|
72 |
zip_file = zip_images(frames)
|
|
|
77 |
interpolated_frames = interpolate_frames(frames, factor=2)
|
78 |
enhanced_frames = enhance_gif(interpolated_frames)
|
79 |
gif_file = create_gif_imageio(enhanced_frames, duration=50, loop=0)
|
80 |
+
|
81 |
+
# Preview the first frame of the GIF
|
82 |
+
preview_image = Image.fromarray(enhanced_frames[0])
|
83 |
+
preview_image.save(os.path.join(GENERATED_FILES_DIR, "preview_frame.png"))
|
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")
|
|
|
105 |
zip_button = gr.Button("Create Zip File")
|
106 |
gif_button = gr.Button("Create GIF")
|
107 |
with gr.Row():
|
108 |
+
preview_image = gr.Image(label="Preview GIF Frame")
|
109 |
zip_output = gr.File(label="Download Zip File")
|
110 |
gif_output = gr.File(label="Download GIF")
|
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 |
|
118 |
demo.launch(show_error=True)
|