jebin2 commited on
Commit
f15162e
·
1 Parent(s): acce059

fix: Make heavy imports lazy in utils.py to allow logger import without all deps

Browse files
Files changed (1) hide show
  1. src/utils.py +12 -7
src/utils.py CHANGED
@@ -1,24 +1,22 @@
1
  """
2
  Utility functions and logging configuration
3
  """
 
4
 
5
  import logging
6
  import sys
7
  from pathlib import Path
8
- import cv2
9
- import numpy as np
10
- from PIL import Image
11
- import imagehash
12
  import subprocess
13
  import os
14
  import uuid
15
  import re
16
  import shutil
17
- import librosa
18
- import pandas as pd
19
- import numpy as np
20
  import tempfile
21
 
 
 
 
 
22
  class ColoredFormatter(logging.Formatter):
23
  """Custom formatter with colors for terminal output"""
24
 
@@ -426,6 +424,8 @@ def calculate_durations_with_fuzzy_matching(selected_videos, word_level_segment,
426
  logger.info(f"✅ Total calculated duration: {total_calculated:.2f}s (expected: {total_duration:.2f}s)")
427
 
428
  def is_video_loopable(video_path, frame_check_window=10, threshold=15.0):
 
 
429
  if not video_path:
430
  return False
431
  cap = cv2.VideoCapture(video_path)
@@ -464,6 +464,9 @@ def is_video_loopable(video_path, frame_check_window=10, threshold=15.0):
464
 
465
 
466
  def is_loopable_phash(video_path, hash_diff_threshold=8):
 
 
 
467
  if not video_path:
468
  return False
469
  cap = cv2.VideoCapture(video_path)
@@ -508,6 +511,8 @@ def is_video_zoomable_tail(video_path, tail_seconds=1, sample_frames=15, motion_
508
  Checks only the *last few seconds* of the video to see if it's already zooming.
509
  Returns True if mostly static (safe to add zoom), False if motion already exists.
510
  """
 
 
511
  return False
512
  cap = cv2.VideoCapture(video_path)
513
  if not cap.isOpened():
 
1
  """
2
  Utility functions and logging configuration
3
  """
4
+ from __future__ import annotations
5
 
6
  import logging
7
  import sys
8
  from pathlib import Path
 
 
 
 
9
  import subprocess
10
  import os
11
  import uuid
12
  import re
13
  import shutil
 
 
 
14
  import tempfile
15
 
16
+ # Note: Heavy imports (cv2, imagehash, librosa, pandas, numpy, PIL) are done
17
+ # lazily inside functions that need them to avoid import errors when only
18
+ # the logger is needed.
19
+
20
  class ColoredFormatter(logging.Formatter):
21
  """Custom formatter with colors for terminal output"""
22
 
 
424
  logger.info(f"✅ Total calculated duration: {total_calculated:.2f}s (expected: {total_duration:.2f}s)")
425
 
426
  def is_video_loopable(video_path, frame_check_window=10, threshold=15.0):
427
+ import cv2
428
+ import numpy as np
429
  if not video_path:
430
  return False
431
  cap = cv2.VideoCapture(video_path)
 
464
 
465
 
466
  def is_loopable_phash(video_path, hash_diff_threshold=8):
467
+ import cv2
468
+ import imagehash
469
+ from PIL import Image
470
  if not video_path:
471
  return False
472
  cap = cv2.VideoCapture(video_path)
 
511
  Checks only the *last few seconds* of the video to see if it's already zooming.
512
  Returns True if mostly static (safe to add zoom), False if motion already exists.
513
  """
514
+ import cv2
515
+ import numpy as np
516
  return False
517
  cap = cv2.VideoCapture(video_path)
518
  if not cap.isOpened():