| """ |
| Legacy Inference Module - Backward Compatibility Interface. |
| |
| This module provides a simplified interface that maintains backward compatibility |
| with the original inference.py while leveraging the new modular architecture. |
| |
| For new development, use the specific modules directly: |
| - video.py: Video classification and play analysis |
| - audio.py: Audio transcription and NFL corrections |
| - config.py: Configuration and constants |
| |
| This module is maintained for: |
| 1. Backward compatibility with existing scripts |
| 2. Simple single-clip processing interface |
| 3. Legacy CLI functionality |
| """ |
|
|
| import os |
| import sys |
| import json |
| from typing import List, Tuple |
|
|
| |
| from video import predict_clip, analyze_play_state, detect_play_boundaries |
| from audio import transcribe_clip, load_audio, apply_sports_corrections, fuzzy_sports_corrections |
| from config import DEFAULT_DATA_DIR |
|
|
| |
| __all__ = [ |
| 'predict_clip', |
| 'analyze_play_state', |
| 'detect_play_boundaries', |
| 'transcribe_clip', |
| 'load_audio', |
| 'apply_sports_corrections', |
| 'fuzzy_sports_corrections' |
| ] |
|
|
|
|
| def main(): |
| """ |
| CLI interface for single clip processing (backward compatibility). |
| |
| Usage: |
| python inference.py path/to/clip.mov |
| """ |
| if len(sys.argv) < 2: |
| print("Usage: python inference.py <path_to_video_clip>") |
| print(f"Example: python inference.py {DEFAULT_DATA_DIR}/segment_001.mov") |
| sys.exit(1) |
| |
| clip_path = sys.argv[1] |
| |
| if not os.path.exists(clip_path): |
| print(f"Error: File '{clip_path}' not found") |
| sys.exit(1) |
| |
| print(f"Processing: {clip_path}") |
| print("=" * 50) |
| |
| |
| print("🎬 Video Classification:") |
| predictions = predict_clip(clip_path) |
| |
| if predictions: |
| print(f"\nTop-5 labels for {clip_path}:") |
| for label, score in predictions: |
| print(f"{label:>30s} : {score:.3f}") |
| |
| |
| clip_name = os.path.basename(clip_path) |
| with open("classification.json", "w") as f: |
| json.dump({clip_name: predictions}, f, indent=2) |
| print(f"\n✓ Classification saved to classification.json") |
| else: |
| print("❌ Video classification failed") |
| |
| |
| print("\n🎙️ Audio Transcription:") |
| transcript = transcribe_clip(clip_path) |
| |
| if transcript: |
| print(f"Transcript: {transcript}") |
| |
| |
| clip_name = os.path.basename(clip_path) |
| with open("transcripts.json", "w") as f: |
| json.dump({clip_name: transcript}, f, indent=2) |
| print(f"✓ Transcript saved to transcripts.json") |
| else: |
| print("ℹ️ No audio content detected or transcription failed") |
| |
| print("\n🏁 Processing complete!") |
|
|
|
|
| if __name__ == "__main__": |
| main() |