ankitverma304 commited on
Commit
820447b
Β·
verified Β·
1 Parent(s): d804d2d

Upload 15 files

Browse files
Files changed (4) hide show
  1. app.py +35 -0
  2. app/video_processor.py +3 -3
  3. main.py +1 -1
  4. requirements.txt +1 -1
app.py CHANGED
@@ -6,6 +6,41 @@ This file imports the fully-built `demo` object from main.py so all logic
6
  stays in one place, then calls demo.launch() for local/Docker runs.
7
  """
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  from main import demo # noqa: F401 β€” `demo` must be importable at module level
10
 
11
  if __name__ == "__main__":
 
6
  stays in one place, then calls demo.launch() for local/Docker runs.
7
  """
8
 
9
+ # ── Compatibility shim ────────────────────────────────────────────────────────
10
+ # huggingface_hub >=0.24 removed HfFolder.
11
+ # Some Gradio versions (including 5.0.x) still do
12
+ # `from huggingface_hub import HfFolder, whoami`
13
+ # in their oauth.py at import time, crashing before our code runs.
14
+ # We inject a minimal shim into the module namespace BEFORE importing Gradio
15
+ # so that import succeeds regardless of huggingface_hub version.
16
+ try:
17
+ from huggingface_hub import HfFolder as _ # noqa: F401 β€” present, nothing to do
18
+ except ImportError:
19
+ import sys
20
+ import huggingface_hub as _hfhub
21
+
22
+ class _HfFolderShim:
23
+ """Minimal drop-in for the removed huggingface_hub.HfFolder class."""
24
+
25
+ @staticmethod
26
+ def get_token():
27
+ try:
28
+ return _hfhub.get_token()
29
+ except Exception:
30
+ return None
31
+
32
+ @staticmethod
33
+ def save_token(token: str) -> None:
34
+ pass # no-op; token management is handled by the HF runtime
35
+
36
+ @staticmethod
37
+ def delete_token() -> None:
38
+ pass
39
+
40
+ _hfhub.HfFolder = _HfFolderShim # type: ignore[attr-defined]
41
+ sys.modules["huggingface_hub"].HfFolder = _HfFolderShim # type: ignore[attr-defined]
42
+
43
+ # ── Now safe to import Gradio (and transitively, our app) ────────────────────
44
  from main import demo # noqa: F401 β€” `demo` must be importable at module level
45
 
46
  if __name__ == "__main__":
app/video_processor.py CHANGED
@@ -5,7 +5,7 @@ import traceback
5
  from datetime import datetime
6
  from pathlib import Path
7
 
8
- from moviepy.editor import VideoFileClip, concatenate_videoclips
9
 
10
  from app.utils import format_duration
11
  from config.settings import settings
@@ -45,7 +45,7 @@ def crop_video(video_path: str, segments: list[dict]) -> tuple[str, str]:
45
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
46
  output_path = output_dir / f"short_video_{timestamp}.mp4"
47
 
48
- source: VideoFileClip | None = None
49
  clips: list[VideoFileClip] = []
50
 
51
  try:
@@ -66,7 +66,7 @@ def crop_video(video_path: str, segments: list[dict]) -> tuple[str, str]:
66
  continue
67
 
68
  logger.info(f"Extracting clip: {start:.1f}s β†’ {end:.1f}s")
69
- clips.append(source.subclip(start, end))
70
 
71
  if not clips:
72
  raise ValueError(
 
5
  from datetime import datetime
6
  from pathlib import Path
7
 
8
+ from moviepy import VideoFileClip, concatenate_videoclips # moviepy 2.x API
9
 
10
  from app.utils import format_duration
11
  from config.settings import settings
 
45
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
46
  output_path = output_dir / f"short_video_{timestamp}.mp4"
47
 
48
+ source = None # type: Optional[VideoFileClip]
49
  clips: list[VideoFileClip] = []
50
 
51
  try:
 
66
  continue
67
 
68
  logger.info(f"Extracting clip: {start:.1f}s β†’ {end:.1f}s")
69
+ clips.append(source.subclipped(start, end))
70
 
71
  if not clips:
72
  raise ValueError(
main.py CHANGED
@@ -127,7 +127,7 @@ def _join(lines: list[str]) -> str:
127
  # ── Pipeline function 1: Analyze (generator) ─────────────────────────────────
128
 
129
  def analyze_video(
130
- video_path: str | None,
131
  progress: gr.Progress = gr.Progress(),
132
  ):
133
  """
 
127
  # ── Pipeline function 1: Analyze (generator) ─────────────────────────────────
128
 
129
  def analyze_video(
130
+ video_path, # str | None β€” Optional[str], compatible with Python 3.9+
131
  progress: gr.Progress = gr.Progress(),
132
  ):
133
  """
requirements.txt CHANGED
@@ -4,7 +4,7 @@ torch
4
  torchaudio
5
 
6
  # ── Video processing ──────────────────────────────────────────────────────────
7
- moviepy==1.0.3
8
  ffmpeg-python>=0.2.0
9
  yt-dlp>=2024.1.1
10
 
 
4
  torchaudio
5
 
6
  # ── Video processing ──────────────────────────────────────────────────────────
7
+ moviepy>=2.0.0
8
  ffmpeg-python>=0.2.0
9
  yt-dlp>=2024.1.1
10