akhaliq HF Staff commited on
Commit
fb0d17a
·
1 Parent(s): abca38d

perf: enable multi-threaded video decoding and offload file persistence to background thread

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -160,6 +160,7 @@ def load_video(video_path, max_frames=64):
160
  try:
161
  container = av.open(video_path)
162
  stream = container.streams.video[0]
 
163
  duration = stream.duration
164
  if duration is None or duration <= 0:
165
  # Fallback to full decode for short/broken streams
@@ -248,9 +249,9 @@ def predict(
248
  Streaming inference endpoint with history support.
249
  """
250
  session_id = str(uuid.uuid4())
251
- # Persist files first for audit parity
252
  if files:
253
- persist_uploaded_files(files, session_id)
254
  messages = []
255
 
256
  # Process history
 
160
  try:
161
  container = av.open(video_path)
162
  stream = container.streams.video[0]
163
+ stream.thread_count = 8 # Enable multi-threaded decoding
164
  duration = stream.duration
165
  if duration is None or duration <= 0:
166
  # Fallback to full decode for short/broken streams
 
249
  Streaming inference endpoint with history support.
250
  """
251
  session_id = str(uuid.uuid4())
252
+ # Persist files in background to avoid blocking user (parity audit)
253
  if files:
254
+ threading.Thread(target=persist_uploaded_files, args=(files, session_id), daemon=True).start()
255
  messages = []
256
 
257
  # Process history