Spaces:
Runtime error
Runtime error
Add app files.
Browse files- .gitattributes +0 -35
- 2023-10-15-daily-demo-screenshot.png +0 -0
- README.md +18 -4
- app.py +72 -0
- example.gif +0 -0
.gitattributes
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-15-daily-demo-screenshot.png
ADDED
README.md
CHANGED
@@ -1,13 +1,27 @@
|
|
1 |
---
|
2 |
title: Gif Reverser
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.47.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: Gif Reverser
|
3 |
+
emoji: π
|
4 |
+
colorFrom: orange
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.47.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
+
tags:
|
12 |
+
- daily-demos
|
13 |
+
- daily-demos-2023-10-15
|
14 |
+
- gradio
|
15 |
---
|
16 |
|
17 |
+
# 2023-10-15 Daily Demo - Gif Reverser
|
18 |
+
|
19 |
+
A daily demo space created by [@gstaff](https://huggingface.co/gstaff).
|
20 |
+
|
21 |
+
## Description
|
22 |
+
A gif reverser utility using gradio.
|
23 |
+
|
24 |
+
![screenshot](2023-10-15-daily-demo-screenshot.png "Screenshot")
|
25 |
+
|
26 |
+
## Credits
|
27 |
+
Example image taken from Google images.
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
|
6 |
+
def reverse(input_path, frames_per_second):
|
7 |
+
# Open the GIF file
|
8 |
+
gif = Image.open(input_path)
|
9 |
+
|
10 |
+
# Get the number of frames in the GIF
|
11 |
+
num_frames = gif.n_frames
|
12 |
+
|
13 |
+
# Create a list to hold the reversed frames
|
14 |
+
reversed_frames = []
|
15 |
+
|
16 |
+
# Iterate through the frames in reverse order
|
17 |
+
for frame_number in range(num_frames, 0, -1):
|
18 |
+
gif.seek(frame_number - 1)
|
19 |
+
frame = gif.copy()
|
20 |
+
reversed_frames.append(frame)
|
21 |
+
|
22 |
+
# Interesting blur effect on gifs with transparent background
|
23 |
+
if 'duration' not in gif.info:
|
24 |
+
# Default is 8 frames per second from AnimatedDiff
|
25 |
+
duration = frames_per_second * num_frames
|
26 |
+
gif.info['duration'] = duration
|
27 |
+
|
28 |
+
# Save the reversed frames as a new GIF
|
29 |
+
with tempfile.NamedTemporaryFile(suffix=".gif", delete=False) as temp_file:
|
30 |
+
temp_filename = temp_file.name
|
31 |
+
reversed_frames[0].save(temp_filename, save_all=True, append_images=reversed_frames[1:],
|
32 |
+
duration=gif.info['duration'], loop=0)
|
33 |
+
return temp_filename
|
34 |
+
|
35 |
+
|
36 |
+
def reverse_gifs(input_paths, frames_per_second):
|
37 |
+
if input_paths is None:
|
38 |
+
return None, None
|
39 |
+
input_paths = [f.name for f in input_paths]
|
40 |
+
|
41 |
+
temp_filenames = []
|
42 |
+
for input_path in input_paths:
|
43 |
+
temp_filenames.append(reverse(input_path, frames_per_second))
|
44 |
+
|
45 |
+
return input_paths, temp_filenames
|
46 |
+
|
47 |
+
|
48 |
+
with gr.Blocks(theme='gstaff/sketch') as demo:
|
49 |
+
gr.Markdown(value='# GIF Reversing Tool')
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=1):
|
52 |
+
gr.Markdown('## Load animated gifs to reverse')
|
53 |
+
image_in = gr.Files(label="Input Gif Files", type='file', file_types=['.gif'])
|
54 |
+
frame_rate = gr.Number(label="Frames per Second to use (if not in gif metadata)", value=8, minimum=1,
|
55 |
+
maximum=360, step=1, interactive=True)
|
56 |
+
image_display = gr.Gallery(label="Input Images", interactive=False)
|
57 |
+
with gr.Column(scale=1):
|
58 |
+
gr.Markdown('## View the reversed gif')
|
59 |
+
image_out = gr.Gallery(label="Reversed Gif Images")
|
60 |
+
clear_button = gr.ClearButton(components=[image_in])
|
61 |
+
|
62 |
+
image_in.change(reverse_gifs, [image_in, frame_rate], [image_display, image_out])
|
63 |
+
gr.Examples(examples=[[['./example.gif'], 8]],
|
64 |
+
inputs=[image_in, frame_rate], outputs=[image_display, image_out], fn=reverse_gifs, cache_examples=True)
|
65 |
+
|
66 |
+
with gr.Accordion('Developer Notes:', open=False):
|
67 |
+
gr.Markdown('This gif reverser is a simple utility I made for myself.\n\n'
|
68 |
+
'The default of 8 frames per second works for the default settings of [AnimateDiff](https://github.com/continue-revolution/sd-webui-animatediff).\n\n'
|
69 |
+
'Future enhancements could be to auto-determine the framerate when otherwise not available in the gif metadata.')
|
70 |
+
|
71 |
+
if __name__ == '__main__':
|
72 |
+
demo.launch()
|
example.gif
ADDED