Shalmoni commited on
Commit
e283869
·
verified ·
1 Parent(s): 7d6ee20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -308,15 +308,41 @@ def generate_keyframe_image(
308
  # MoviePy lazy install/import
309
  # =========================
310
  def _ensure_moviepy():
 
 
 
 
 
311
  try:
312
  from moviepy.editor import ImageClip, CompositeVideoClip, concatenate_videoclips
313
  from moviepy.video.io.VideoFileClip import VideoFileClip
314
  return ImageClip, CompositeVideoClip, concatenate_videoclips, VideoFileClip
315
  except Exception:
316
- subprocess.check_call([sys.executable, "-m", "pip", "install", "moviepy", "imageio", "imageio-ffmpeg"])
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  from moviepy.editor import ImageClip, CompositeVideoClip, concatenate_videoclips
318
  from moviepy.video.io.VideoFileClip import VideoFileClip
319
  return ImageClip, CompositeVideoClip, concatenate_videoclips, VideoFileClip
 
 
 
 
 
 
 
 
320
 
321
  # =========================
322
  # Video stitching (pairwise dissolve + final concat)
 
308
  # MoviePy lazy install/import
309
  # =========================
310
  def _ensure_moviepy():
311
+ """
312
+ Import MoviePy lazily. If unavailable, try a best-effort pip install.
313
+ If that still fails, raise a clear Gradio error telling the user to rebuild.
314
+ Also wires up the bundled ffmpeg from imageio-ffmpeg.
315
+ """
316
  try:
317
  from moviepy.editor import ImageClip, CompositeVideoClip, concatenate_videoclips
318
  from moviepy.video.io.VideoFileClip import VideoFileClip
319
  return ImageClip, CompositeVideoClip, concatenate_videoclips, VideoFileClip
320
  except Exception:
321
+ pass # will try to install below
322
+
323
+ # Try to install at runtime (some Spaces block this)
324
+ try:
325
+ import sys, subprocess
326
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "-q",
327
+ "moviepy==1.0.3", "imageio>=2.34.0", "imageio-ffmpeg>=0.4.9"])
328
+ # Point MoviePy to a known-good ffmpeg
329
+ try:
330
+ import imageio_ffmpeg, os as _os
331
+ _os.environ["IMAGEIO_FFMPEG_EXE"] = imageio_ffmpeg.get_ffmpeg_exe()
332
+ except Exception:
333
+ pass
334
+ # Try importing again
335
  from moviepy.editor import ImageClip, CompositeVideoClip, concatenate_videoclips
336
  from moviepy.video.io.VideoFileClip import VideoFileClip
337
  return ImageClip, CompositeVideoClip, concatenate_videoclips, VideoFileClip
338
+ except Exception as e:
339
+ # Final, friendly failure with next steps
340
+ import gradio as gr
341
+ raise gr.Error(
342
+ "MoviePy is not available. Add `moviepy==1.0.3`, `imageio>=2.34.0`, "
343
+ "`imageio-ffmpeg>=0.4.9` to requirements.txt and restart/rebuild the Space. "
344
+ f"(Runtime install failed with: {type(e).__name__}: {e})"
345
+ )
346
 
347
  # =========================
348
  # Video stitching (pairwise dissolve + final concat)