From 01776f6f4dabb527ac84b5399d16f83285c4ef07 Mon Sep 17 00:00:00 2001 From: Yxjiang <2237303+yxjiang@users.noreply.github.com> Date: Thu, 7 Aug 2025 05:27:21 -0700 Subject: [PATCH] cleanup --- .../media-gen/integration_tests/README.md | 110 --------------- .../integration_tests/test_image.png | 3 - .../test_image_understanding.py | 92 ------------- .../test_openai_image_gen.py | 110 --------------- .../test_replicate_image_gen.py | 118 ---------------- .../test_replicate_video_gen.py | 127 ------------------ .../integration_tests/test_video.mp4 | 3 - .../test_video_understanding_tool.py | 126 ----------------- .../integration_tests/test_video_utils.py | 94 ------------- 9 files changed, 783 deletions(-) delete mode 100644 examples/media-gen/integration_tests/README.md delete mode 100644 examples/media-gen/integration_tests/test_image.png delete mode 100644 examples/media-gen/integration_tests/test_image_understanding.py delete mode 100644 examples/media-gen/integration_tests/test_openai_image_gen.py delete mode 100644 examples/media-gen/integration_tests/test_replicate_image_gen.py delete mode 100644 examples/media-gen/integration_tests/test_replicate_video_gen.py delete mode 100644 examples/media-gen/integration_tests/test_video.mp4 delete mode 100644 examples/media-gen/integration_tests/test_video_understanding_tool.py delete mode 100644 examples/media-gen/integration_tests/test_video_utils.py diff --git a/examples/media-gen/integration_tests/README.md b/examples/media-gen/integration_tests/README.md deleted file mode 100644 index 087c45a..0000000 --- a/examples/media-gen/integration_tests/README.md +++ /dev/null @@ -1,110 +0,0 @@ -# Integration Tests - -This folder contains integration tests that require real API calls and external resources. - -## OpenAI Image Generation Integration Test - -### Prerequisites -- OpenAI API key in `.env` file -- Internet connection -- OpenAI API access with verified organization (for image generation) - -### Running the Test - -```bash -# From the media-gen directory -python integration_tests/test_openai_image_gen.py -``` - -### What it does -- Generates a single image with a specific whimsical prompt -- Tests the OpenAI image generation tool with real API calls -- Saves the generated image to `~/Downloads/polymind_generated_images/` -- Provides helpful error messages for common issues - -### Expected Output -The test will show: -- āœ… Confirmation that API key is found -- šŸŽØ Image generation progress -- šŸ“ File path and size of generated image -- šŸŽÆ Generation metadata - -### Generated Image -- Dynamically named image with timestamp (e.g., `openai_generated_image_20241201_143022.png`) - -### Notes -- This test is not run automatically with unit tests -- It requires a valid OpenAI API key -- It makes real API calls and may incur costs -- Generated images are saved in `~/Downloads/polymind_generated_images/` with unique names -- If you get an organization verification error, follow the provided instructions - -## Replicate Image Generation Integration Test - -### Prerequisites -- Replicate API token in `.env` file -- Internet connection -- Replicate API access - -### Running the Test - -```bash -# From the media-gen directory -python integration_tests/test_replicate_image_gen.py -``` - -### What it does -- Generates a single image with a cinematic cat prompt -- Tests the Replicate image generation tool with real API calls -- Saves the generated image to `~/Downloads/polymind_generated_images/` -- Provides helpful error messages for common issues - -### Expected Output -The test will show: -- āœ… Confirmation that API token is found -- šŸŽØ Image generation progress -- šŸ“ File path and size of generated image -- šŸŽÆ Generation metadata - -### Generated Image -- Dynamically named image with timestamp (e.g., `replicate_generated_image_20241201_143022.jpeg`) - -### Notes -- This test is not run automatically with unit tests -- It requires a valid Replicate API token -- It makes real API calls and may incur costs -- Generated images are saved in `~/Downloads/polymind_generated_images/` with unique names -- Uses the WAN 2.2 model by default - -## Image Understanding Integration Test - -### Prerequisites -- OpenAI API key in `.env` file -- Internet connection -- Test image file (`test_image.png`) - -### Running the Test - -```bash -# From the media-gen directory -python integration_tests/test_image_understanding.py -``` - -### What it does -- Loads the test image (`test_image.png`) -- Generates an image generation prompt that could be used to recreate the image -- Calls OpenAI's GPT-4o-mini API -- Displays the generated prompt and metadata - -### Expected Output -The test will show: -- āœ… Confirmation that test image and API key are found -- šŸ“ The prompt being used -- šŸ“‹ The generated image generation prompt -- šŸ“Š Token usage metadata - -### Notes -- This test is not run automatically with unit tests -- It requires a valid OpenAI API key -- It makes real API calls and may incur costs -- The test image should be placed in this folder \ No newline at end of file diff --git a/examples/media-gen/integration_tests/test_image.png b/examples/media-gen/integration_tests/test_image.png deleted file mode 100644 index 5e0ac2f..0000000 --- a/examples/media-gen/integration_tests/test_image.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e0d1ea17f7ac0f64778cb6ff0b21c7a2157058181320fd9ee211db130a2e8f7b -size 3431060 diff --git a/examples/media-gen/integration_tests/test_image_understanding.py b/examples/media-gen/integration_tests/test_image_understanding.py deleted file mode 100644 index 5a9d7a6..0000000 --- a/examples/media-gen/integration_tests/test_image_understanding.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple integration test for ImageUnderstandingTool. - -This test uses the test_image.png file to generate an image generation prompt. -It requires OPENAI_API_KEY in the .env file. - -Run with: python integration_tests/test_image_understanding.py -""" - -import os -import sys - -from dotenv import load_dotenv -from pathlib import Path - -# Add the parent directory to the path to import the tool -sys.path.insert(0, str(Path(__file__).parent.parent)) - -from tools.image_understanding_tool import ImageUnderstandingTool - - -def main(): - """Run the integration test.""" - print("=== Image Understanding Integration Test ===") - print("This test will analyze test_image.png and generate an image generation prompt.\n") - - # Load environment variables - load_dotenv() - - # Check for OpenAI API key - api_key = os.getenv("OPENAI_API_KEY") - if not api_key: - print("āŒ Error: OPENAI_API_KEY not found in environment.") - print("Please set it in your .env file.") - return - - # Get test image path - test_image_path = Path(__file__).parent / "test_image.png" - - if not test_image_path.exists(): - print(f"āŒ Error: Test image not found at {test_image_path}") - return - - print(f"āœ… Found test image: {test_image_path}") - print(f"āœ… API key available: {api_key[:8]}...") - print() - - # Initialize tool - tool = ImageUnderstandingTool() - - # Define the prompt for image generation - prompt = ( - "Analyze this image and create an image generation prompt that could be used " - "to recreate this image as similar as possible. " - "Include specific details about objects, characters, setting, " - "lighting, mood, image style, composition, colors, and textures. The prompt should be " - "less than 100 words." - ) - - print("šŸ“ Prompt: Generate image generation prompt") - print("šŸ”„ Calling OpenAI API...") - - try: - result = tool.run({ - "prompt": prompt, - "images": [str(test_image_path)], - "return_json": False, - "max_tokens": 600 - }) - - print("āœ… Analysis completed successfully!") - print("\nšŸ“‹ Generated Image Generation Prompt:") - print("-" * 50) - print(result["analysis"]) - print("-" * 50) - - print("\nšŸ“Š Metadata:") - print(f" Model: {result['metadata']['model']}") - print(f" Total tokens: {result['metadata']['tokens_used']}") - print(f" Prompt tokens: {result['metadata']['prompt_tokens']}") - print(f" Completion tokens: {result['metadata']['completion_tokens']}") - - except Exception as e: - print(f"āŒ Error during analysis: {e}") - return - - print("\nāœ… Integration test completed successfully!") - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/examples/media-gen/integration_tests/test_openai_image_gen.py b/examples/media-gen/integration_tests/test_openai_image_gen.py deleted file mode 100644 index d8028aa..0000000 --- a/examples/media-gen/integration_tests/test_openai_image_gen.py +++ /dev/null @@ -1,110 +0,0 @@ -""" -Integration test for OpenAI image generation tool. - -This script tests the OpenAI image generation tool with a real API call. -It generates a single image with a specific prompt and saves it to ~/Downloads. - -Requirements: -- Valid OpenAI API key in environment variables -- Internet connection -- OpenAI API access -""" - -import os -import sys - -from dotenv import load_dotenv -from pathlib import Path - -# Add parent directory to path for imports -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - -from tools.openai_image_gen import OpenAIImageGen - - -def main(): - """Generate a single image with the specified prompt.""" - print("šŸš€ OpenAI Image Generation Integration Test") - print("=" * 60) - - # Check if OpenAI API key is available - if not os.getenv("OPENAI_API_KEY"): - print("āŒ OPENAI_API_KEY environment variable not set") - print("Please set your OpenAI API key to run integration tests") - return - - print(f"āœ… OpenAI API key found: {os.getenv('OPENAI_API_KEY')[:10]}...") - - # Create Downloads directory if it doesn't exist - downloads_dir = Path.home() / "Downloads" / "polymind_generated_images" - downloads_dir.mkdir(parents=True, exist_ok=True) - print(f"āœ… Output directory: {downloads_dir.absolute()}") - - # Initialize the tool - image_gen = OpenAIImageGen() - - # The specific prompt provided by the user - prompt = ( - "Create a whimsical scene inside a modern subway train featuring a " - "fluffy, light brown rabbit and a chubby, soft gray penguin sitting " - "side by side on blue plastic seats. The background includes tall " - "city buildings visible through a large window and a colorful framed " - "picture on the wall. Soft, natural lighting filtering through the " - "window enhances the cheerful atmosphere. The image should be " - "hyper-realistic with fine textures on the animals' fur and " - "feathers, emphasizing their cuteness while maintaining a playful " - "and friendly mood." - ) - - print("\nšŸŽØ Generating image with prompt:") - print(f"'{prompt[:100]}...'") - print() - - try: - # Generate the image - result = image_gen.run({ - "prompt": prompt, - "size": "1024x1024", - "quality": "high", - "output_format": "png", - "output_folder": str(downloads_dir) - }) - - print(f"Result: {result}") - - if result["image_path"] and os.path.exists(result["image_path"]): - file_size = os.path.getsize(result["image_path"]) - print("āœ… Image generated successfully!") - print(f"šŸ“ Saved to: {result['image_path']}") - print(f"šŸ“ File size: {file_size:,} bytes") - print(f"šŸŽÆ Generation info: {result['generation_info']}") - else: - print("āŒ Image generation failed") - error_msg = result.get('generation_info', {}).get('error', 'Unknown error') - print(f"Error: {error_msg}") - - # Check for specific error types and provide helpful guidance - if "organization must be verified" in error_msg.lower(): - print("\nšŸ’” To fix this issue:") - print("1. Go to: https://platform.openai.com/settings/organization/general") - print("2. Click on 'Verify Organization'") - print("3. Wait up to 15 minutes for access to propagate") - print("4. Try running this test again") - elif "api key" in error_msg.lower(): - print("\nšŸ’” To fix this issue:") - print("1. Check that your OPENAI_API_KEY is correct") - print("2. Ensure you have sufficient credits in your OpenAI account") - print("3. Verify your account has access to image generation features") - - except Exception as e: - print(f"\nāŒ Integration test failed with error: {e}") - import traceback - traceback.print_exc() - - -if __name__ == "__main__": - # Load environment variables - load_dotenv() - - # Run the integration test - main() \ No newline at end of file diff --git a/examples/media-gen/integration_tests/test_replicate_image_gen.py b/examples/media-gen/integration_tests/test_replicate_image_gen.py deleted file mode 100644 index 842d2f6..0000000 --- a/examples/media-gen/integration_tests/test_replicate_image_gen.py +++ /dev/null @@ -1,118 +0,0 @@ -""" -Integration test for Replicate image generation tool. - -This script tests the Replicate image generation tool with real API calls. -It should be run manually when you want to test the actual image generation -functionality. - -Requirements: -- Valid Replicate API token in environment variables -- Internet connection -- Replicate API access -""" - -import os -import sys - -from dotenv import load_dotenv -from pathlib import Path - -# Add parent directory to path for imports -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - -try: - from tools.replicate_image_gen import ReplicateImageGen -except ImportError as e: - if "replicate" in str(e): - print("āŒ Replicate package not installed. Please install it with:") - print(" pip install replicate") - sys.exit(1) - else: - raise - - -def main(): - """Generate a single image with the specified prompt.""" - print("šŸš€ Replicate Image Generation Integration Test") - print("=" * 60) - - # Check if Replicate API token is available - if not os.getenv("REPLICATE_API_TOKEN"): - print("āŒ REPLICATE_API_TOKEN environment variable not set") - print("Please set your Replicate API token to run integration tests") - return - - token = os.getenv('REPLICATE_API_TOKEN') - print(f"āœ… Replicate API token found: {token[:10]}...") - - # Create Downloads directory if it doesn't exist - downloads_dir = Path.home() / "Downloads" / "polymind_generated_images" - downloads_dir.mkdir(parents=True, exist_ok=True) - print(f"āœ… Output directory: {downloads_dir.absolute()}") - - # Initialize the tool - image_gen = ReplicateImageGen() - - # The specific prompt from the example - prompt = ( - "Create a whimsical scene inside a modern subway train featuring a " - "fluffy, light brown rabbit and a chubby, soft gray penguin sitting " - "side by side on blue plastic seats. The background includes tall " - "city buildings visible through a large window and a colorful framed " - "picture on the wall. Soft, natural lighting filtering through the " - "window enhances the cheerful atmosphere. The image should be " - "hyper-realistic with fine textures on the animals' fur and " - "feathers, emphasizing their cuteness while maintaining a playful " - "and friendly mood." - ) - - print("\nšŸŽØ Generating image with prompt:") - print(f"'{prompt[:100]}...'") - print() - - try: - # Generate the image - result = image_gen.run({ - "prompt": prompt, - "seed": 246764, - "aspect_ratio": "4:3", - "output_folder": str(downloads_dir) - }) - - print(f"Result: {result}") - - if result["image_path"] and os.path.exists(result["image_path"]): - file_size = os.path.getsize(result["image_path"]) - print("āœ… Image generated successfully!") - print(f"šŸ“ Saved to: {result['image_path']}") - print(f"šŸ“ File size: {file_size:,} bytes") - print(f"šŸŽÆ Generation info: {result['generation_info']}") - else: - print("āŒ Image generation failed") - error_msg = result.get('generation_info', {}).get('error', 'Unknown error') - print(f"Error: {error_msg}") - - # Check for specific error types and provide helpful guidance - if "api token" in error_msg.lower(): - print("\nšŸ’” To fix this issue:") - print("1. Check that your REPLICATE_API_TOKEN is correct") - print("2. Ensure you have sufficient credits in your Replicate account") - print("3. Verify your account has access to the model") - elif "model" in error_msg.lower(): - print("\nšŸ’” To fix this issue:") - print("1. Check that the model name is correct") - print("2. Ensure the model is publicly available") - print("3. Verify your account has access to the model") - - except Exception as e: - print(f"\nāŒ Integration test failed with error: {e}") - import traceback - traceback.print_exc() - - -if __name__ == "__main__": - # Load environment variables - load_dotenv() - - # Run the integration test - main() \ No newline at end of file diff --git a/examples/media-gen/integration_tests/test_replicate_video_gen.py b/examples/media-gen/integration_tests/test_replicate_video_gen.py deleted file mode 100644 index 8ab9349..0000000 --- a/examples/media-gen/integration_tests/test_replicate_video_gen.py +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env python3 -""" -Simple script to generate videos using Replicate's WAN 2.2 i2v fast model. - -Usage: - python integration_tests/test_replicate_video_gen.py [image_path] [prompt] \ - [--timeout SECONDS] [--progress-interval SECONDS] - -Examples: - python integration_tests/test_replicate_video_gen.py - python integration_tests/test_replicate_video_gen.py test_image.png \ - "animals playing football" - python integration_tests/test_replicate_video_gen.py /path/to/image.jpg \ - "a magical forest scene" - python integration_tests/test_replicate_video_gen.py test_image.png \ - "magical scene" --timeout 300 --progress-interval 10 - -Requirements: -- REPLICATE_API_TOKEN environment variable set -- Default test image: integration_tests/test_image.png -""" - -import os -import sys - -from dotenv import load_dotenv -from pathlib import Path - -# Add parent directory to path for imports -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - -# Load environment variables from .env file -load_dotenv(os.path.join(os.path.dirname(__file__), '..', '.env')) - -from tools.replicate_video_gen import ReplicateVideoGen - - -def main(): - """Generate a video from an image and prompt using Replicate.""" - # Check for API token - if not os.getenv("REPLICATE_API_TOKEN"): - print("āŒ REPLICATE_API_TOKEN not found in environment variables") - print("Please set: export REPLICATE_API_TOKEN='your_token_here'") - sys.exit(1) - - # Parse command line arguments - if len(sys.argv) > 1: - image_path = sys.argv[1] - # If it's a relative path, make it relative to the script directory - if not Path(image_path).is_absolute(): - image_path = Path(__file__).parent / image_path - else: - # Default to test image - image_path = Path(__file__).parent / "test_image.png" - - if len(sys.argv) > 2: - prompt = sys.argv[2] - else: - # Default prompt - prompt = "the animals standup and start playing football" - - # Parse optional timeout and progress interval - timeout = 600 # 10 minutes default - progress_interval = 5 # 5 seconds default - - # Simple argument parsing for timeout and progress interval - for i, arg in enumerate(sys.argv[3:], 3): - if arg == "--timeout" and i + 1 < len(sys.argv): - timeout = int(sys.argv[i + 1]) - elif arg == "--progress-interval" and i + 1 < len(sys.argv): - progress_interval = int(sys.argv[i + 1]) - - # Validate image path - if not Path(image_path).exists(): - print(f"āŒ Image not found: {image_path}") - sys.exit(1) - - print(f"šŸŽ¬ Generating video from: {image_path}") - print(f"šŸ“ Prompt: {prompt}") - print("šŸ“ Output: ~/Downloads/polymind_video_generation/") - print("-" * 60) - - # Initialize and run video generation - video_gen = ReplicateVideoGen() - - # Debug: Check if image exists and get its size - image_path_obj = Path(image_path) - if image_path_obj.exists(): - size_mb = image_path_obj.stat().st_size / (1024 * 1024) - print(f"šŸ“ Input image size: {size_mb:.2f} MB") - else: - print(f"āŒ Image file not found: {image_path}") - sys.exit(1) - - # Expand the output folder path - output_folder = os.path.expanduser("~/Downloads/polymind_video_generation") - - try: - result = video_gen.run({ - "image": str(image_path), - "prompt": prompt, - "output_folder": output_folder, - "output_format": "mp4", - "timeout": timeout, - "progress_interval": progress_interval - }) - - if result["video_path"]: - print("āœ… Video generated successfully!") - print(f"šŸ“ Saved to: {result['video_path']}") - - # Show file size if available - video_path = Path(result["video_path"]) - if video_path.exists(): - size_mb = video_path.stat().st_size / (1024 * 1024) - print(f"šŸ“ File size: {size_mb:.1f} MB") - else: - print(f"āŒ Generation failed: {result['generation_info']}") - sys.exit(1) - - except Exception as e: - print(f"āŒ Error: {e}") - sys.exit(1) - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/examples/media-gen/integration_tests/test_video.mp4 b/examples/media-gen/integration_tests/test_video.mp4 deleted file mode 100644 index 9502e09..0000000 --- a/examples/media-gen/integration_tests/test_video.mp4 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ac1bb2cde2a13877b15d6a01bba65e4c0b835c9692e80f62478f5df7a95a0438 -size 6988797 diff --git a/examples/media-gen/integration_tests/test_video_understanding_tool.py b/examples/media-gen/integration_tests/test_video_understanding_tool.py deleted file mode 100644 index ba35483..0000000 --- a/examples/media-gen/integration_tests/test_video_understanding_tool.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env python3 -""" -Integration test for VideoUnderstandingTool. - -This script tests the VideoUnderstandingTool with test_video.mp4 using either -interval-based or keyframe-based extraction methods. - -Requirements: -- Valid OpenAI API key in environment variables -- test_video.mp4 file in the integration_tests directory -- Internet connection -- OpenAI API access - -Run with: python integration_tests/test_video_understanding_tool.py [--interval] -""" - -import argparse -import os -import sys - -from dotenv import load_dotenv -from pathlib import Path - -# Add the parent directory to the path to import the tool -sys.path.insert(0, str(Path(__file__).parent.parent)) - -from tools.video_understanding_tool import VideoUnderstandingTool - - -def test_extraction(tool, test_video_path, use_interval=False): - """Test video extraction with specified method.""" - if use_interval: - print("šŸ“ø Testing Interval-Based Extraction") - print("-" * 40) - - result = tool.run({ - "video_path": str(test_video_path), - "user_preference": "cinematic style with dramatic lighting", - "extraction_mode": "interval", - "screenshot_interval": 10.0, - "output_dir": "~/Downloads/video_understanding_interval" - }) - - print("āœ… Interval-based analysis completed!") - print(f"šŸ“Š Scenes: {result['metadata']['total_scenes']}") - print(f"ā±ļø Duration: {result['metadata']['video_duration']}") - print(f"šŸ“ø Interval: {result['metadata']['screenshot_interval']}") - - else: - print("šŸ” Testing Keyframe-Based Extraction") - print("-" * 40) - - result = tool.run({ - "video_path": str(test_video_path), - "user_preference": "cinematic style with dramatic lighting", - "extraction_mode": "keyframe", - "keyframe_threshold": 25.0, - "min_interval_frames": 15, - "output_dir": "~/Downloads/video_understanding_keyframe" - }) - - print("āœ… Keyframe-based analysis completed!") - print(f"šŸ“Š Scenes: {result['metadata']['total_scenes']}") - print(f"ā±ļø Duration: {result['metadata']['video_duration']}") - print(f"šŸŽÆ Threshold: {result['metadata']['keyframe_threshold']}") - - return len(result["image_prompts"]) - - -def main(): - """Run the integration test.""" - # Parse command line arguments - parser = argparse.ArgumentParser( - description="Test VideoUnderstandingTool with different extraction methods" - ) - parser.add_argument( - "--interval", - action="store_true", - help="Use interval-based extraction (default: keyframe-based)" - ) - args = parser.parse_args() - - extraction_method = "interval" if args.interval else "keyframe" - - print("=== Video Understanding Integration Test ===") - print(f"This test will analyze test_video.mp4 using {extraction_method}-based extraction.\n") - - # Load environment variables - load_dotenv() - - # Check for OpenAI API key - api_key = os.getenv("OPENAI_API_KEY") - if not api_key: - print("āŒ Error: OPENAI_API_KEY not found in environment.") - print("Please set it in your .env file.") - return - - # Get test video path - test_video_path = Path(__file__).parent / "test_video.mp4" - - if not test_video_path.exists(): - print(f"āŒ Error: Test video not found at {test_video_path}") - print("Please place a test video file named 'test_video.mp4' in the " - "integration_tests directory.") - return - - print(f"āœ… Found test video: {test_video_path}") - print(f"āœ… API key available: {api_key[:8]}...") - print() - - # Initialize tool - tool = VideoUnderstandingTool() - - # Test extraction method - try: - scene_count = test_extraction(tool, test_video_path, args.interval) - print(f"\nšŸ“Š Results: {scene_count} scenes detected") - print("\nāœ… Integration test completed successfully!") - - except Exception as e: - print(f"āŒ Test failed: {e}") - return - - -if __name__ == "__main__": - main() diff --git a/examples/media-gen/integration_tests/test_video_utils.py b/examples/media-gen/integration_tests/test_video_utils.py deleted file mode 100644 index 2daa8a8..0000000 --- a/examples/media-gen/integration_tests/test_video_utils.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python3 -""" -Integration test for video screenshot extraction utilities. - -This script demonstrates video screenshot extraction functionality using the test video. -It extracts screenshots every 10 seconds and saves them to ~/Downloads. - -Usage: - python integration_tests/test_video_utils.py - -Requirements: -- OpenCV (opencv-python) -- Test video file: integration_tests/test_video.mp4 -""" - -import os -import sys - -from pathlib import Path - -# Add parent directory to path for imports -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) - -from utils.video_utils import VideoScreenshotExtractor, extract_screenshots - - -def main(): - """Extract screenshots from the test video every 10 seconds.""" - print("šŸŽ¬ Video Screenshot Extraction Test") - print("=" * 50) - - # Path to test video - test_video_path = Path(__file__).parent / "test_video.mp4" - - if not test_video_path.exists(): - print(f"āŒ Test video not found at: {test_video_path}") - print("Please ensure test_video.mp4 exists in the integration_tests directory") - return - - print(f"āœ… Test video found: {test_video_path}") - print(f"šŸ“ File size: {test_video_path.stat().st_size:,} bytes") - - # Get video properties - with VideoScreenshotExtractor(str(test_video_path)) as extractor: - print(f"šŸŽ„ Video properties:") - print(f" - FPS: {extractor.fps:.2f}") - print(f" - Duration: {extractor.duration:.2f} seconds") - print(f" - Frame count: {extractor.frame_count:,}") - print() - - # Extract screenshots every 5 seconds, starting from 1 second - print("šŸ”„ Extracting screenshots every 5 seconds (starting from 1s)...") - print("-" * 50) - - try: - screenshots = extract_screenshots( - video_path=str(test_video_path), - interval_seconds=5.0, - start_time=1.0, # Start from 1 second instead of 0 - output_dir="~/Downloads/polymind_video_screenshots", - filename_prefix="test_video_5s" - ) - - print(f"āœ… Extracted {len(screenshots)} screenshots") - for i, ss in enumerate(screenshots): - print(f" {i+1}. Frame {ss.frame_number} at {ss.timestamp_str}") - print() - - except Exception as e: - print(f"āŒ Screenshot extraction failed: {e}") - return - - # Summary - print("šŸ“Š Summary") - print("=" * 50) - downloads_dir = Path.home() / "Downloads" / "polymind_video_screenshots" - - if downloads_dir.exists(): - screenshot_files = list(downloads_dir.glob("test_video_10s_*.jpg")) - print(f"āœ… Screenshots saved to: {downloads_dir}") - print(f"šŸ“ Files created: {len(screenshot_files)}") - - if screenshot_files: - print(f"šŸ“„ File pattern: test_video_10s_*.jpg") - print(f"šŸ“ Sample file size: {screenshot_files[0].stat().st_size:,} bytes") - else: - print("āŒ No screenshots were created") - - print("\nšŸŽÆ Test completed!") - print("šŸ’” You can now view the extracted screenshots in your Downloads folder") - - -if __name__ == "__main__": - main()