hperkins commited on
Commit
21e3017
1 Parent(s): 03e2ec1

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +12 -1
handler.py CHANGED
@@ -39,6 +39,9 @@ class EndpointHandler():
39
  )
40
  image_inputs, video_inputs = process_vision_info(messages)
41
 
 
 
 
42
  inputs = self.processor(
43
  text=[text],
44
  images=image_inputs,
@@ -69,7 +72,9 @@ class EndpointHandler():
69
  else: # Image/video part
70
  if part.lower().startswith("video:"):
71
  video_path = part.split("video:")[1].strip()
 
72
  video_frames = self._extract_video_frames(video_path)
 
73
  if video_frames:
74
  content.append({"type": "video", "video": video_frames, "fps": 1})
75
  else:
@@ -102,13 +107,19 @@ class EndpointHandler():
102
  def _extract_video_frames(self, video_path, fps=1):
103
  """Extracts frames from a video at the specified FPS using MoviePy."""
104
  try:
 
105
  video = VideoFileClip(video_path)
 
 
106
  frames = [
107
  Image.fromarray(frame.astype('uint8'), 'RGB')
108
  for frame in video.iter_frames(fps=fps)
109
  ]
 
 
 
110
  video.close()
111
  return frames
112
  except Exception as e:
113
- logging.error(f"Error extracting video frames: {e}")
114
  return None
 
39
  )
40
  image_inputs, video_inputs = process_vision_info(messages)
41
 
42
+ logging.debug(f"Image inputs: {image_inputs}") # Log image inputs
43
+ logging.debug(f"Video inputs: {video_inputs}") # Log video inputs
44
+
45
  inputs = self.processor(
46
  text=[text],
47
  images=image_inputs,
 
72
  else: # Image/video part
73
  if part.lower().startswith("video:"):
74
  video_path = part.split("video:")[1].strip()
75
+ print(f"Video path: {video_path}") # Print video path
76
  video_frames = self._extract_video_frames(video_path)
77
+ print(f"Number of frames extracted: {len(video_frames) if video_frames else 0}") # Print frame count
78
  if video_frames:
79
  content.append({"type": "video", "video": video_frames, "fps": 1})
80
  else:
 
107
  def _extract_video_frames(self, video_path, fps=1):
108
  """Extracts frames from a video at the specified FPS using MoviePy."""
109
  try:
110
+ print(f"Attempting to load video from: {video_path}") # Print before loading
111
  video = VideoFileClip(video_path)
112
+ print(f"Video loaded: {video}") # Print after loading
113
+
114
  frames = [
115
  Image.fromarray(frame.astype('uint8'), 'RGB')
116
  for frame in video.iter_frames(fps=fps)
117
  ]
118
+ print(f"Number of frames: {len(frames)}") # Check frame count
119
+ print(f"Frame type: {type(frames[0]) if frames else None}") # Check frame type
120
+ print(f"Frame size: {frames[0].size if frames else None}") # Check frame size
121
  video.close()
122
  return frames
123
  except Exception as e:
124
+ logging.error(f"Error extracting video frames: {e}", exc_info=True) # Log exception details
125
  return None