tori29umai commited on
Commit
69520b1
·
verified ·
1 Parent(s): 4cd9bef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -25,7 +25,7 @@ def process_image(image_path):
25
  width = int(height * aspect_ratio)
26
  image = image.resize((width, height), Image.ANTIALIAS)
27
 
28
- # 画像を5秒の動画にするためのフレーム数を決定(例えば30fpsで5秒分なので150フレーム)
29
  fps = 30
30
  duration = 5
31
  total_frames = fps * duration
@@ -37,8 +37,8 @@ def process_image(image_path):
37
  frame = np.array(image)
38
  frames.append(frame)
39
 
40
- # 動画保存先のパス
41
- output_video_path = os.path.splitext(image_path)[0] + '.mp4'
42
 
43
  # 動画ファイルにフレームを保存
44
  fourcc = cv2.VideoWriter_fourcc(*'mp4v') # MP4形式
@@ -51,6 +51,7 @@ def process_image(image_path):
51
 
52
  video_writer.release()
53
 
 
54
  return output_video_path
55
 
56
  class WebUI:
@@ -70,7 +71,7 @@ class WebUI:
70
  with gr.Row():
71
  with gr.Column():
72
  with gr.Tab("Output"):
73
- output_mp4 = gr.Gallery()
74
  submit.click(self.main, inputs=[input_image], outputs=[output_mp4])
75
 
76
  self.demo.queue()
 
25
  width = int(height * aspect_ratio)
26
  image = image.resize((width, height), Image.ANTIALIAS)
27
 
28
+ # 動画のフレーム数(30fpsで5秒分)
29
  fps = 30
30
  duration = 5
31
  total_frames = fps * duration
 
37
  frame = np.array(image)
38
  frames.append(frame)
39
 
40
+ # 動画保存先の一時ファイルパス
41
+ output_video_path = "/tmp/output_video.mp4"
42
 
43
  # 動画ファイルにフレームを保存
44
  fourcc = cv2.VideoWriter_fourcc(*'mp4v') # MP4形式
 
51
 
52
  video_writer.release()
53
 
54
+ # 動画ファイルをGradioに返す
55
  return output_video_path
56
 
57
  class WebUI:
 
71
  with gr.Row():
72
  with gr.Column():
73
  with gr.Tab("Output"):
74
+ output_mp4 = gr.Video()
75
  submit.click(self.main, inputs=[input_image], outputs=[output_mp4])
76
 
77
  self.demo.queue()