Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,42 @@
|
|
|
|
1 |
from PIL import Image, ImageSequence
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
frame
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from PIL import Image, ImageSequence
|
3 |
|
4 |
+
def edit_gif(gif_file, loop_count, speed_factor, frame_skip):
|
5 |
+
# GIFを読み込む
|
6 |
+
gif = Image.open(gif_file)
|
7 |
+
frames = []
|
8 |
+
durations = []
|
9 |
|
10 |
+
# フレームを順に処理
|
11 |
+
for i, frame in enumerate(ImageSequence.Iterator(gif)):
|
12 |
+
# 指定したフレーム数ごとにスキップ
|
13 |
+
if i % frame_skip != 0:
|
14 |
+
continue
|
15 |
+
frames.append(frame.copy())
|
16 |
+
durations.append(gif.info.get("duration", 100) // speed_factor) # 再生速度調整
|
17 |
|
18 |
+
# 新しいGIFを保存
|
19 |
+
output_path = "edited.gif"
|
20 |
+
frames[0].save(
|
21 |
+
output_path,
|
22 |
+
save_all=True,
|
23 |
+
append_images=frames[1:],
|
24 |
+
loop=loop_count,
|
25 |
+
duration=durations,
|
26 |
+
disposal=2
|
27 |
+
)
|
28 |
+
return output_path
|
29 |
+
|
30 |
+
# Gradioインターフェース
|
31 |
+
interface = gr.Interface(
|
32 |
+
fn=edit_gif,
|
33 |
+
inputs=[
|
34 |
+
gr.File(label="アップロードするGIF"),
|
35 |
+
gr.Number(label="ループ回数(0は無限ループ)", value=0),
|
36 |
+
gr.Number(label="再生速度の倍率(例: 2は2倍速)", value=1),
|
37 |
+
gr.Number(label="フレームスキップ数", value=1),
|
38 |
+
],
|
39 |
+
outputs=gr.File(label="編集されたGIF")
|
40 |
+
)
|
41 |
+
|
42 |
+
interface.launch()
|