Spaces:
Runtime error
Runtime error
| """Application file.""" | |
| from zipfile import ZipFile | |
| import os | |
| import imageio | |
| import gradio as gr | |
| def create_gif(filenames, name_gif): | |
| filenames = sorted(filenames) | |
| images = [] | |
| for filename in filenames: | |
| images.append(imageio.imread(filename)) | |
| kargs = {"duration": 2.00} | |
| imageio.mimsave(name_gif, images, "GIF", **kargs) | |
| def upload_file(file): | |
| folder_name = file.name.split(".")[0] | |
| print(folder_name) | |
| print("EXTRACTING ....") | |
| # Extract the zip file | |
| with ZipFile(file.name, "r") as zObject: | |
| # Extracting specific file in the zip | |
| # into a specific location. | |
| zObject.extractall(path=folder_name) | |
| zip_filename = os.listdir(folder_name)[0] | |
| filenames = os.listdir(f"{folder_name}/{zip_filename}") | |
| filenames = sorted(filenames) | |
| filenames = [f"{folder_name}/{zip_filename}/{name}" for name in filenames] | |
| create_gif(filenames, "created_gif.gif") | |
| return "created_gif.gif" | |
| with gr.Blocks() as demo: | |
| gr.Markdown(""" | |
| If you have a sequence of images, that you want to turn a gif, you can use this app to do so. | |
| Folder Structure: | |
| folder_name | |
| |- epoch001.png | |
| |- epoch002.png | |
| |- epoch003.png | |
| |- ... | |
| └── epoch100.png | |
| Turn this folder into a zip: | |
| ```shell | |
| zip -r folder_name.zip folder_name | |
| ``` | |
| Upload this zip file and the app will create a gif for you. | |
| """) | |
| output_gif = gr.Image() | |
| upload_button = gr.UploadButton( | |
| label="Click to Upload a Zip file", | |
| ) | |
| upload_button.upload( | |
| upload_file, | |
| inputs=upload_button, | |
| outputs=output_gif, | |
| ) | |
| demo.launch() |