admin commited on
Commit
4377031
·
1 Parent(s): dda06b5
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -17,9 +17,7 @@ def clean_cache(tmp_dir=TMP_DIR):
17
 
18
 
19
  def get_frame_duration(gif: Image):
20
- # 获取 GIF 图像中第一帧的 duration
21
  duration = gif.info.get("duration", 100)
22
- # 返回每一帧的 duration
23
  return [
24
  frame.info.get("duration", duration) for frame in ImageSequence.Iterator(gif)
25
  ]
@@ -43,7 +41,6 @@ def resize_gif(
43
  modified_frames.append(resized_frame)
44
 
45
  frame_durations = get_frame_duration(gif)
46
- # 将修改后的帧作为新的 GIF 保存
47
  modified_frames[0].save(
48
  output_path,
49
  format="GIF",
@@ -62,7 +59,7 @@ def infer(video_path: str, speed: float):
62
  try:
63
  with VideoFileClip(video_path, audio_fps=16000) as clip:
64
  if clip.duration > 5:
65
- raise ValueError("上传的视频过长 The uploaded video is too long")
66
 
67
  # clip.write_gif(gif_path, fps=12, progress_bar=True)
68
  clip.speedx(speed).to_gif(gif_path, fps=12)
@@ -79,9 +76,9 @@ if __name__ == "__main__":
79
  gr.Interface(
80
  fn=infer,
81
  inputs=[
82
- gr.Video(label="上传视频 Upload video"),
83
  gr.Slider(
84
- label="倍速 Speed",
85
  minimum=0.5,
86
  maximum=2.0,
87
  step=0.25,
@@ -89,9 +86,9 @@ if __name__ == "__main__":
89
  ),
90
  ],
91
  outputs=[
92
- gr.Textbox(label="文件名 Filename", show_copy_button=True),
93
- gr.Image(label="下载动图 Download GIF", type="filepath"),
94
  ],
95
- title="请确保视频上传完整后再点击提交,若时长大于五秒可先在线裁剪<br>Please make sure the video is completely uploaded before clicking Submit, you can crop it online first if the video size is >5s",
96
  flagging_mode="never",
97
  ).launch()
 
17
 
18
 
19
  def get_frame_duration(gif: Image):
 
20
  duration = gif.info.get("duration", 100)
 
21
  return [
22
  frame.info.get("duration", duration) for frame in ImageSequence.Iterator(gif)
23
  ]
 
41
  modified_frames.append(resized_frame)
42
 
43
  frame_durations = get_frame_duration(gif)
 
44
  modified_frames[0].save(
45
  output_path,
46
  format="GIF",
 
59
  try:
60
  with VideoFileClip(video_path, audio_fps=16000) as clip:
61
  if clip.duration > 5:
62
+ raise ValueError("The uploaded video is too long")
63
 
64
  # clip.write_gif(gif_path, fps=12, progress_bar=True)
65
  clip.speedx(speed).to_gif(gif_path, fps=12)
 
76
  gr.Interface(
77
  fn=infer,
78
  inputs=[
79
+ gr.Video(label="Upload video"),
80
  gr.Slider(
81
+ label="Speed",
82
  minimum=0.5,
83
  maximum=2.0,
84
  step=0.25,
 
86
  ),
87
  ],
88
  outputs=[
89
+ gr.Textbox(label="Filename", show_copy_button=True),
90
+ gr.Image(label="Download GIF", type="filepath"),
91
  ],
92
+ title="Please make sure the video is completely uploaded before clicking Submit, you can crop it online first if the video size is >5s",
93
  flagging_mode="never",
94
  ).launch()