File size: 2,937 Bytes
ed2222b
 
f6e44ec
ed2222b
 
f6e44ec
ed2222b
 
 
 
f6e44ec
ed2222b
 
 
 
 
7701582
ed2222b
 
 
 
 
 
 
 
5988ab2
ed2222b
 
 
 
 
 
 
 
 
 
 
f6e44ec
 
ed2222b
1bf4ae1
ed2222b
1bf4ae1
ed2222b
 
1bf4ae1
ed2222b
 
5988ab2
ed2222b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bf4ae1
ed2222b
 
 
1bf4ae1
ed2222b
 
1bf4ae1
ed2222b
 
 
 
 
 
 
1bf4ae1
ed2222b
1bf4ae1
f6e44ec
 
ed2222b
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
"""
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

# Import from new modular structure
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

# Re-export all functions for backward compatibility
__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)
    
    # Video classification
    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}")
        
        # Save classification results
        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")
    
    # Audio transcription
    print("\n🎙️ Audio Transcription:")
    transcript = transcribe_clip(clip_path)
    
    if transcript:
        print(f"Transcript: {transcript}")
        
        # Save transcript results
        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()