soiz commited on
Commit
e9c4020
·
verified ·
1 Parent(s): 51e5e37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -8
app.py CHANGED
@@ -1,12 +1,42 @@
 
1
  from PIL import Image, ImageSequence
2
 
3
- gif = Image.open('example.gif')
4
- frames = []
 
 
 
5
 
6
- for frame in ImageSequence.Iterator(gif):
7
- frame = frame.convert("RGBA")
8
- # 編集処理例: サイズ変更
9
- frame = frame.resize((100, 100))
10
- frames.append(frame)
 
 
11
 
12
- frames[0].save('edited.gif', save_all=True, append_images=frames[1:], loop=0, duration=gif.info['duration'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()