VeuReu commited on
Commit
75e7233
verified
1 Parent(s): 3055650

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -37
app.py CHANGED
@@ -140,43 +140,48 @@ def face_image_embedding(image: Image.Image) -> List[float] | None:
140
  def scenes_extraction(video_file: str, threshold: float, offset_frames: int, crop_ratio: float) -> Tuple[List[Image.Image], List[Dict]] | None:
141
  # video_file es un str ya que aunque realmente el usuario subi贸 un archivo desde la UI, Gradio lo guarda temporalmente como ruta
142
 
143
- # Detectamos las escenas
144
- video_manager = VideoManager([video_file])
145
- scene_manager = SceneManager()
146
- scene_manager.add_detector(ContentDetector(threshold=threshold))
147
- video_manager.start()
148
- scene_manager.detect_scenes(video_manager)
149
- scene_list = scene_manager.get_scene_list()
150
-
151
- cap = cv2.VideoCapture(video_file)
152
- images: List[Image.Image] = []
153
- informacion_escenas: List[Dict] = []
154
-
155
- for i, (start_time, end_time) in enumerate(scene_list):
156
- frame_number = int(start_time.get_frames()) + offset_frames
157
- cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
158
- ret, frame = cap.read()
159
- if ret:
160
- h, w = frame.shape[:2]
161
-
162
- # Ahora realizamos el recorte
163
- ch, cw = int(h * crop_ratio), int(w * crop_ratio)
164
- frame = frame[ch:h-ch, cw:w-cw]
165
-
166
- # Guardamos la escena obtenida
167
- frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
168
- img = Image.fromarray(frame_rgb)
169
- images.append(img)
170
-
171
- # Guardamos la informaci贸n de la escena
172
- informacion_escenas.append({
173
- "index": i+1,
174
- "start": start_time.get_seconds(),
175
- "end": end_time.get_seconds()
176
- })
177
-
178
- cap.release()
179
- return images, informacion_escenas
 
 
 
 
 
180
 
181
  # ----------------------------- UI & Endpoints --------------------------------
182
 
 
140
  def scenes_extraction(video_file: str, threshold: float, offset_frames: int, crop_ratio: float) -> Tuple[List[Image.Image], List[Dict]] | None:
141
  # video_file es un str ya que aunque realmente el usuario subi贸 un archivo desde la UI, Gradio lo guarda temporalmente como ruta
142
 
143
+ try:
144
+ # Detectamos las escenas
145
+ video_manager = VideoManager([video_file])
146
+ scene_manager = SceneManager()
147
+ scene_manager.add_detector(ContentDetector(threshold=threshold))
148
+ video_manager.start()
149
+ scene_manager.detect_scenes(video_manager)
150
+ scene_list = scene_manager.get_scene_list()
151
+
152
+ cap = cv2.VideoCapture(video_file)
153
+ images: List[Image.Image] = []
154
+ informacion_escenas: List[Dict] = []
155
+
156
+ for i, (start_time, end_time) in enumerate(scene_list):
157
+ frame_number = int(start_time.get_frames()) + offset_frames
158
+ cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
159
+ ret, frame = cap.read()
160
+ if ret:
161
+ h, w = frame.shape[:2]
162
+
163
+ # Ahora realizamos el recorte
164
+ ch, cw = int(h * crop_ratio), int(w * crop_ratio)
165
+ frame = frame[ch:h-ch, cw:w-cw]
166
+
167
+ # Guardamos la escena obtenida
168
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
169
+ img = Image.fromarray(frame_rgb)
170
+ images.append(img)
171
+
172
+ # Guardamos la informaci贸n de la escena
173
+ informacion_escenas.append({
174
+ "index": i+1,
175
+ "start": start_time.get_seconds(),
176
+ "end": end_time.get_seconds()
177
+ })
178
+
179
+ cap.release()
180
+ return images, informacion_escenas
181
+
182
+ except Exception as e:
183
+ print("Error en scenes_extraction:", e)
184
+ return [], []
185
 
186
  # ----------------------------- UI & Endpoints --------------------------------
187