Spaces:
Running
Running
File size: 4,477 Bytes
8a74c03 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
#!/usr/bin/env python3
"""
Test the new People Counter functionality
"""
import sys
import os
from io import BytesIO
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_people_counter():
"""Test the People Counter model"""
print("TESTING PEOPLE COUNTER MODEL")
print("=" * 40)
try:
from local_models import get_local_model_manager
from app import extract_frames_from_video, process_image_locally
print("+ Successfully imported components")
except ImportError as e:
print(f"- Import error: {e}")
return
# Find video file
video_files = [f for f in os.listdir('.') if f.endswith('.mp4')]
if not video_files:
print("- No MP4 files found")
return
video_path = video_files[0]
print(f"+ Using video: {video_path[:40]}...")
# Initialize models
try:
local_manager = get_local_model_manager()
available_models = local_manager.get_available_models()
print(f"+ Available models: {available_models}")
if "People Counter" not in available_models:
print("- People Counter model not found!")
return
print("+ People Counter model ready")
except Exception as e:
print(f"- Model initialization error: {e}")
return
# Extract frames for testing
try:
with open(video_path, 'rb') as f:
video_data = f.read()
video_file = BytesIO(video_data)
frames = extract_frames_from_video(video_file, fps=0.2) # Every 5 seconds
if not frames:
print("- No frames extracted")
return
print(f"+ Extracted {len(frames)} frames for testing")
# Test with 3 frames
test_frames = frames[:3]
except Exception as e:
print(f"- Frame extraction error: {e}")
return
# Test People Counter on each frame
print(f"\nTesting People Counter on {len(test_frames)} frames:")
print("=" * 60)
for i, frame_data in enumerate(test_frames):
frame_num = i + 1
timestamp = frame_data['timestamp']
print(f"\nFRAME {frame_num} (t={timestamp:.1f}s)")
print("-" * 30)
try:
result = process_image_locally(
frame_data['frame'],
"Track Safety Analysis", # This will be ignored by People Counter
'People Counter',
local_manager
)
if 'error' in result:
print(f"ERROR: {result['error']}")
elif 'people_analysis' in result:
analysis = result['people_analysis']
# Display main results
print(f"People Count: {analysis.get('people_count', 0)}")
print(f"On Tracks: {analysis.get('on_tracks', False)}")
print(f"Safety Risk: {analysis.get('safety_risk', False)}")
print(f"Confidence: {analysis.get('confidence', 0):.1%}")
print(f"Summary: {analysis.get('analysis_summary', 'N/A')}")
# Show detailed analysis
responses = analysis.get('detailed_responses', {})
print(f"\nDetailed Analysis:")
for key, data in list(responses.items())[:2]: # Show first 2 analyses
prompt = data.get('prompt', 'N/A')
response = data.get('response', 'N/A')
print(f" Q: {prompt}")
print(f" A: {response}")
else:
print(f"Unexpected result format: {result}")
except Exception as e:
print(f"ERROR: {e}")
print(f"\n" + "=" * 60)
print("PEOPLE COUNTER TEST SUMMARY")
print("=" * 60)
print("+ People Counter model successfully integrated")
print("+ Provides comprehensive safety analysis")
print("+ Uses multiple specialized prompts for accuracy")
print("+ Ready for use in Streamlit app at http://localhost:8502")
print(f"\nNext steps:")
print("1. Open http://localhost:8502")
print("2. Select 'People Counter' from model dropdown")
print("3. Upload your video")
print("4. Click 'Process Video' for detailed safety analysis")
if __name__ == "__main__":
test_people_counter() |