not-lain KingNish commited on
Commit
8365126
1 Parent(s): de54836

Update app.py (#2)

Browse files

- Update app.py (07b6e2157f03e204ec1afd29cb40c7840d356b2a)


Co-authored-by: Nishith Jain <[email protected]>

Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -8,7 +8,9 @@ import moviepy.editor as mp
8
  from pydub import AudioSegment
9
  from PIL import Image
10
  import numpy as np
11
-
 
 
12
 
13
  torch.set_float32_matmul_precision(["high", "highest"][0])
14
 
@@ -48,9 +50,15 @@ def fn(vid):
48
  # Add the original audio back to the processed video
49
  processed_video = processed_video.set_audio(audio)
50
 
51
- # Return the processed video
52
- return processed_video
 
 
 
 
53
 
 
 
54
 
55
 
56
  def process(image):
 
8
  from pydub import AudioSegment
9
  from PIL import Image
10
  import numpy as np
11
+ import os
12
+ import tempfile
13
+ import uuid
14
 
15
  torch.set_float32_matmul_precision(["high", "highest"][0])
16
 
 
50
  # Add the original audio back to the processed video
51
  processed_video = processed_video.set_audio(audio)
52
 
53
+ # Save the processed video to a temporary file
54
+ temp_dir = "temp"
55
+ os.makedirs(temp_dir, exist_ok=True)
56
+ unique_filename = str(uuid.uuid4()) + ".mp4"
57
+ temp_filepath = os.path.join(temp_dir, unique_filename)
58
+ processed_video.write_videofile(temp_filepath, codec="libx264")
59
 
60
+ # Return the path to the temporary file
61
+ return temp_filepath
62
 
63
 
64
  def process(image):