kavehtaheri commited on
Commit
c83ff8b
·
verified ·
1 Parent(s): b12b399

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -3,8 +3,10 @@ import requests
3
  import os
4
  import json
5
  import time
6
- # CORRECT, HIGH-LEVEL IMPORT for MoviePy. This brings in all editing functions.
7
- from moviepy.editor import VideoFileClip
 
 
8
  import traceback # Import traceback for detailed error logging
9
 
10
  # --- 1. CONFIGURATION & CONSTANTS ---
@@ -155,10 +157,17 @@ def generate_viral_clip(video_file, srt_file, analysis_mode, progress=gr.Progres
155
  return f"An unexpected error occurred in the main process: {str(e)}\n\nTraceback:\n{tb_str}", None
156
 
157
  finally:
 
158
  if new_clip:
159
- new_clip.close()
 
 
 
160
  if video:
161
- video.close()
 
 
 
162
 
163
  # --- 4. GRADIO UI DEFINITION ---
164
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
@@ -192,4 +201,3 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
192
 
193
  if __name__ == "__main__":
194
  demo.launch(debug=True)
195
-
 
3
  import os
4
  import json
5
  import time
6
+ # CORRECTED IMPORT FOR RESTRICTED ENVIRONMENTS:
7
+ # We bypass the 'editor' module and import the class directly.
8
+ # This works now because requirements.txt ensures a full installation.
9
+ from moviepy.video.io.VideoFileClip import VideoFileClip
10
  import traceback # Import traceback for detailed error logging
11
 
12
  # --- 1. CONFIGURATION & CONSTANTS ---
 
157
  return f"An unexpected error occurred in the main process: {str(e)}\n\nTraceback:\n{tb_str}", None
158
 
159
  finally:
160
+ # Gracefully close the video clips to release file handles
161
  if new_clip:
162
+ try:
163
+ new_clip.close()
164
+ except Exception:
165
+ pass # Ignore errors on close
166
  if video:
167
+ try:
168
+ video.close()
169
+ except Exception:
170
+ pass # Ignore errors on close
171
 
172
  # --- 4. GRADIO UI DEFINITION ---
173
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
201
 
202
  if __name__ == "__main__":
203
  demo.launch(debug=True)