bravedims commited on
Commit
7b4fc5d
Β·
1 Parent(s): 1be0a9c

Fix inference script NameError and add placeholder video generation

Browse files

πŸ› Issue: NameError: name 'logger' is not defined in inference.py line 69
❌ Error: Logger was being used but not properly initialized

πŸ”§ Fixes:
- Add proper logging.basicConfig() and logger initialization
- Fix get_device() function to use initialized logger
- Add comprehensive main() function with error handling
- Implement placeholder video generation using OpenCV
- Add proper sample processing and output handling

βœ… Features:
- Creates animated placeholder videos (moving circle + text)
- Proper device auto-detection (CPU/GPU)
- Error handling for each sample
- Detailed logging throughout the process
- MP4 output with configurable FPS and duration

πŸ“ Current Behavior:
- Generates 5-second placeholder videos instead of actual avatars
- Shows 'Avatar Placeholder Frame X' with animated circle
- Ensures the full pipeline works end-to-end
- Future: Will be replaced with actual OmniAvatar model inference

Files changed (1) hide show
  1. scripts/inference.py +69 -15
scripts/inference.py CHANGED
@@ -6,7 +6,9 @@ import sys
6
  from pathlib import Path
7
  import logging
8
 
9
-
 
 
10
 
11
  def get_device(config_device):
12
  """Auto-detect available device"""
@@ -57,36 +59,88 @@ def process_input_file(input_file):
57
  })
58
  return samples
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  def main():
61
  args = parse_args()
62
 
 
 
 
63
  # Load configuration
64
  config = load_config(args.config)
65
 
 
 
 
 
66
  # Process input samples
67
  samples = process_input_file(args.input_file)
68
-
69
  logger.info(f"Processing {len(samples)} samples")
70
 
 
 
 
 
71
  # Create output directory
72
  output_dir = Path(config['output']['output_dir'])
73
  output_dir.mkdir(exist_ok=True)
74
 
75
- # This is a placeholder - actual inference would require the OmniAvatar model implementation
76
- logger.info("Note: This is a placeholder inference script.")
77
- logger.info("Actual implementation would require:")
78
- logger.info("1. Loading the OmniAvatar model")
79
- logger.info("2. Processing audio with wav2vec2")
80
- logger.info("3. Running video generation pipeline")
81
- logger.info("4. Saving output videos")
82
-
83
  for i, sample in enumerate(samples):
84
- logger.info(f"Sample {i+1}: {sample['prompt']}")
85
- logger.info(f" Audio: {sample['audio_path']}")
86
- logger.info(f" Image: {sample['image_path']}")
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- logger.info("Inference completed successfully!")
 
 
89
 
90
  if __name__ == "__main__":
91
  main()
92
-
 
6
  from pathlib import Path
7
  import logging
8
 
9
+ # Set up logging
10
+ logging.basicConfig(level=logging.INFO)
11
+ logger = logging.getLogger(__name__)
12
 
13
  def get_device(config_device):
14
  """Auto-detect available device"""
 
59
  })
60
  return samples
61
 
62
+ def create_placeholder_video(output_path, duration=5.0, fps=24):
63
+ """Create a simple placeholder video"""
64
+ import numpy as np
65
+ import cv2
66
+
67
+ logger.info(f"Creating placeholder video: {output_path}")
68
+
69
+ # Video properties
70
+ width, height = 480, 480
71
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
72
+
73
+ # Create video writer
74
+ out = cv2.VideoWriter(str(output_path), fourcc, fps, (width, height))
75
+
76
+ # Generate frames
77
+ total_frames = int(duration * fps)
78
+ for frame_idx in range(total_frames):
79
+ # Create a simple animated frame
80
+ frame = np.zeros((height, width, 3), dtype=np.uint8)
81
+
82
+ # Add some animation - moving circle
83
+ center_x = int(width/2 + 100 * np.sin(2 * np.pi * frame_idx / 60))
84
+ center_y = int(height/2 + 50 * np.cos(2 * np.pi * frame_idx / 60))
85
+
86
+ # Draw circle
87
+ cv2.circle(frame, (center_x, center_y), 30, (0, 255, 0), -1)
88
+
89
+ # Add text
90
+ text = f"Avatar Placeholder Frame {frame_idx + 1}"
91
+ font = cv2.FONT_HERSHEY_SIMPLEX
92
+ cv2.putText(frame, text, (10, 30), font, 0.5, (255, 255, 255), 1)
93
+
94
+ out.write(frame)
95
+
96
+ out.release()
97
+ logger.info(f"βœ… Placeholder video created: {output_path}")
98
+
99
  def main():
100
  args = parse_args()
101
 
102
+ logger.info("πŸš€ Starting OmniAvatar-14B Inference")
103
+ logger.info(f"Arguments: {args}")
104
+
105
  # Load configuration
106
  config = load_config(args.config)
107
 
108
+ # Auto-detect device
109
+ device = get_device(config["hardware"]["device"])
110
+ config["hardware"]["device"] = device
111
+
112
  # Process input samples
113
  samples = process_input_file(args.input_file)
 
114
  logger.info(f"Processing {len(samples)} samples")
115
 
116
+ if not samples:
117
+ logger.error("No valid samples found in input file")
118
+ return
119
+
120
  # Create output directory
121
  output_dir = Path(config['output']['output_dir'])
122
  output_dir.mkdir(exist_ok=True)
123
 
124
+ # Process each sample
 
 
 
 
 
 
 
125
  for i, sample in enumerate(samples):
126
+ logger.info(f"Processing sample {i+1}/{len(samples)}: {sample['prompt'][:50]}...")
127
+
128
+ # For now, create a placeholder video
129
+ output_filename = f"avatar_output_{i:03d}.mp4"
130
+ output_path = output_dir / output_filename
131
+
132
+ try:
133
+ # Create placeholder video (in the future, this would be actual avatar generation)
134
+ create_placeholder_video(output_path, duration=5.0, fps=24)
135
+
136
+ logger.info(f"βœ… Sample {i+1} completed: {output_path}")
137
+
138
+ except Exception as e:
139
+ logger.error(f"❌ Error processing sample {i+1}: {e}")
140
 
141
+ logger.info("πŸŽ‰ Inference completed!")
142
+ logger.info("πŸ“ Note: Currently generating placeholder videos.")
143
+ logger.info("πŸ”œ Future updates will include actual OmniAvatar model inference.")
144
 
145
  if __name__ == "__main__":
146
  main()