seawolf2357 commited on
Commit
e2ad603
1 Parent(s): 5f5104c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -5,31 +5,24 @@ import tempfile
5
  from pathlib import Path
6
 
7
  def image_to_video(input_file, fps=30):
8
- # Create a temporary directory to store the image
9
  with tempfile.TemporaryDirectory() as temp_dir:
10
  file_path = os.path.join(temp_dir, "image.jpg")
11
  with open(file_path, 'wb') as file:
12
  file.write(input_file)
13
 
14
-
15
- # Read the image to set the video size
16
  frame = cv2.imread(file_path)
17
  height, width, layers = frame.shape
18
  size = (width, height)
19
 
20
- # Create a unique filename for the output video
21
  video_filename = os.path.join('/mnt/data', 'output_video.mp4')
22
 
23
- # Initialize the video writer
24
  out = cv2.VideoWriter(video_filename, cv2.VideoWriter_fourcc(*'mp4v'), fps, size)
25
-
26
- # Add the image to the video
27
  out.write(frame)
28
-
29
- # Release the video writer
30
  out.release()
31
-
32
- # Return the path of the created video file
 
 
33
  return video_filename
34
 
35
  iface = gr.Interface(
 
5
  from pathlib import Path
6
 
7
  def image_to_video(input_file, fps=30):
 
8
  with tempfile.TemporaryDirectory() as temp_dir:
9
  file_path = os.path.join(temp_dir, "image.jpg")
10
  with open(file_path, 'wb') as file:
11
  file.write(input_file)
12
 
 
 
13
  frame = cv2.imread(file_path)
14
  height, width, layers = frame.shape
15
  size = (width, height)
16
 
 
17
  video_filename = os.path.join('/mnt/data', 'output_video.mp4')
18
 
 
19
  out = cv2.VideoWriter(video_filename, cv2.VideoWriter_fourcc(*'mp4v'), fps, size)
 
 
20
  out.write(frame)
 
 
21
  out.release()
22
+
23
+ if not os.path.exists(video_filename):
24
+ raise FileNotFoundError(f"Failed to create video: {video_filename}")
25
+
26
  return video_filename
27
 
28
  iface = gr.Interface(