Update vision_analyzer.py
Browse files- vision_analyzer.py +10 -9
vision_analyzer.py
CHANGED
|
@@ -133,7 +133,7 @@ def log_message(message: str):
|
|
| 133 |
def log_failed_file(filename: str, error: str):
|
| 134 |
"""Log failed files to persistent file"""
|
| 135 |
with open(FAILED_FILES_LOG, "a") as f:
|
| 136 |
-
f.write(f"{time.strftime(
|
| 137 |
|
| 138 |
def get_disk_usage(path: str) -> Dict[str, float]:
|
| 139 |
"""Get disk usage statistics in GB"""
|
|
@@ -330,8 +330,8 @@ def analyze_single_frame(image_path: str, preprompt: str = "") -> dict:
|
|
| 330 |
|
| 331 |
# Process with proper padding configuration
|
| 332 |
inputs = vision_processor(
|
| 333 |
-
images=image,
|
| 334 |
-
text=preprompt,
|
| 335 |
return_tensors="pt",
|
| 336 |
padding="max_length",
|
| 337 |
max_length=512,
|
|
@@ -380,9 +380,9 @@ def process_video_frames(frames_dir: str, video_filename: str, output_file: str)
|
|
| 380 |
# Validate first frame
|
| 381 |
first_frame_result = analyze_single_frame(str(frames[0]), get_preprompt(video_filename))
|
| 382 |
print("\n=== FIRST FRAME VALIDATION ===")
|
| 383 |
-
print(f"Image: {first_frame_result[
|
| 384 |
-
print(f"Result: {first_frame_result[
|
| 385 |
-
print(f"Status: {
|
| 386 |
|
| 387 |
if not first_frame_result["success"]:
|
| 388 |
print("❌ Aborting due to first frame failure")
|
|
@@ -466,7 +466,7 @@ def process_rar_file(rar_path: str) -> bool:
|
|
| 466 |
# Process each video
|
| 467 |
for video_path in video_files:
|
| 468 |
video_filename = Path(video_path).name
|
| 469 |
-
frames_dir = os.path.join(FRAMES_OUTPUT_FOLDER, f"{course_name}_{video_filename.replace(
|
| 470 |
ensure_dir(frames_dir)
|
| 471 |
|
| 472 |
# Extract frames
|
|
@@ -477,7 +477,7 @@ def process_rar_file(rar_path: str) -> bool:
|
|
| 477 |
processing_status["extracted_frames_count"] += extracted_count
|
| 478 |
|
| 479 |
# Analyze frames
|
| 480 |
-
analysis_output = os.path.join(ANALYSIS_OUTPUT_FOLDER, f"{course_name}_{video_filename.replace(
|
| 481 |
if process_video_frames(frames_dir, video_filename, analysis_output):
|
| 482 |
processing_status["analyzed_frames_count"] += extracted_count
|
| 483 |
processing_status["extracted_videos"] += 1
|
|
@@ -727,4 +727,5 @@ __all__ = [
|
|
| 727 |
"extract_frames",
|
| 728 |
"DEFAULT_FPS",
|
| 729 |
"ensure_dir"
|
| 730 |
-
]
|
|
|
|
|
|
| 133 |
def log_failed_file(filename: str, error: str):
|
| 134 |
"""Log failed files to persistent file"""
|
| 135 |
with open(FAILED_FILES_LOG, "a") as f:
|
| 136 |
+
f.write(f"{time.strftime("%Y-%m-%d %H:%M:%S")} - {filename}: {error}\n")
|
| 137 |
|
| 138 |
def get_disk_usage(path: str) -> Dict[str, float]:
|
| 139 |
"""Get disk usage statistics in GB"""
|
|
|
|
| 330 |
|
| 331 |
# Process with proper padding configuration
|
| 332 |
inputs = vision_processor(
|
| 333 |
+
images=[image], # Wrap the single image in a list
|
| 334 |
+
text=[preprompt], # Wrap the single preprompt in a list
|
| 335 |
return_tensors="pt",
|
| 336 |
padding="max_length",
|
| 337 |
max_length=512,
|
|
|
|
| 380 |
# Validate first frame
|
| 381 |
first_frame_result = analyze_single_frame(str(frames[0]), get_preprompt(video_filename))
|
| 382 |
print("\n=== FIRST FRAME VALIDATION ===")
|
| 383 |
+
print(f"Image: {first_frame_result["image"]}")
|
| 384 |
+
print(f"Result: {first_frame_result["description"]}")
|
| 385 |
+
print(f"Status: {"Success" if first_frame_result["success"] else "Failed"}\n")
|
| 386 |
|
| 387 |
if not first_frame_result["success"]:
|
| 388 |
print("❌ Aborting due to first frame failure")
|
|
|
|
| 466 |
# Process each video
|
| 467 |
for video_path in video_files:
|
| 468 |
video_filename = Path(video_path).name
|
| 469 |
+
frames_dir = os.path.join(FRAMES_OUTPUT_FOLDER, f"{course_name}_{video_filename.replace(".", "_")}_frames")
|
| 470 |
ensure_dir(frames_dir)
|
| 471 |
|
| 472 |
# Extract frames
|
|
|
|
| 477 |
processing_status["extracted_frames_count"] += extracted_count
|
| 478 |
|
| 479 |
# Analyze frames
|
| 480 |
+
analysis_output = os.path.join(ANALYSIS_OUTPUT_FOLDER, f"{course_name}_{video_filename.replace(".", "_")}_analysis.json")
|
| 481 |
if process_video_frames(frames_dir, video_filename, analysis_output):
|
| 482 |
processing_status["analyzed_frames_count"] += extracted_count
|
| 483 |
processing_status["extracted_videos"] += 1
|
|
|
|
| 727 |
"extract_frames",
|
| 728 |
"DEFAULT_FPS",
|
| 729 |
"ensure_dir"
|
| 730 |
+
]
|
| 731 |
+
|