Samfredoly commited on
Commit
563c37b
·
verified ·
1 Parent(s): 0a257b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -437,7 +437,7 @@ async def process_batch_dynamic(wav_files: List[str], start_batch_index: int, ba
437
  # Download the WAV file
438
  wav_path = await download_wav_file_by_index(file_index + 1, wav_file)
439
  if not wav_path:
440
- state["file_states"][wav_filename] = "failed"
441
  await upload_hf_state(state)
442
  print(f"[{FLOW_ID}] ❌ Failed to download {wav_filename}")
443
  continue
@@ -445,7 +445,7 @@ async def process_batch_dynamic(wav_files: List[str], start_batch_index: int, ba
445
  # Assign to server and create task
446
  await assign_file_to_server(file_index, server)
447
  task = asyncio.create_task(send_audio_to_whisper(wav_path, server))
448
- pending_tasks[task] = (file_index, wav_path, server, wav_filename)
449
  print(f"[{FLOW_ID}] Assigned {wav_filename} to server {servers.index(server) + 1}")
450
 
451
  # --- Wait for all tasks in this batch to complete and process results
@@ -456,31 +456,32 @@ async def process_batch_dynamic(wav_files: List[str], start_batch_index: int, ba
456
  )
457
 
458
  for task in done:
459
- file_index, wav_path, server, wav_filename = pending_tasks.pop(task)
 
460
 
461
  try:
462
  transcription_result = task.result()
463
 
464
  if transcription_result:
465
- # Upload transcription immediately
466
- uploaded_ok = await upload_transcription_to_hf(wav_filename, transcription_result)
467
  if uploaded_ok:
468
  # Update state locally but do NOT upload to HF yet
469
- state["file_states"][wav_filename] = "processed"
470
  uploaded_count += 1
471
  progress['uploaded_count'] = uploaded_count
472
  save_progress(progress)
473
  print(f"[{FLOW_ID}] ✅ {wav_filename} uploaded (#{uploaded_count})")
474
  else:
475
- state["file_states"][wav_filename] = "failed"
476
  print(f"[{FLOW_ID}] ❌ Failed to upload {wav_filename}")
477
  else:
478
- state["file_states"][wav_filename] = "failed"
479
  print(f"[{FLOW_ID}] ❌ Transcription failed for {wav_filename}")
480
 
481
  except Exception as e:
482
  print(f"[{FLOW_ID}] Error processing result for {wav_filename}: {e}")
483
- state["file_states"][wav_filename] = "failed"
484
  finally:
485
  # Release the server
486
  await release_server(server)
 
437
  # Download the WAV file
438
  wav_path = await download_wav_file_by_index(file_index + 1, wav_file)
439
  if not wav_path:
440
+ state["file_states"][wav_file] = "failed"
441
  await upload_hf_state(state)
442
  print(f"[{FLOW_ID}] ❌ Failed to download {wav_filename}")
443
  continue
 
445
  # Assign to server and create task
446
  await assign_file_to_server(file_index, server)
447
  task = asyncio.create_task(send_audio_to_whisper(wav_path, server))
448
+ pending_tasks[task] = (file_index, wav_path, server, wav_file)
449
  print(f"[{FLOW_ID}] Assigned {wav_filename} to server {servers.index(server) + 1}")
450
 
451
  # --- Wait for all tasks in this batch to complete and process results
 
456
  )
457
 
458
  for task in done:
459
+ file_index, wav_path, server, wav_file = pending_tasks.pop(task)
460
+ wav_filename = Path(wav_file).name
461
 
462
  try:
463
  transcription_result = task.result()
464
 
465
  if transcription_result:
466
+ # Upload transcription immediately with full path
467
+ uploaded_ok = await upload_transcription_to_hf(wav_file, transcription_result)
468
  if uploaded_ok:
469
  # Update state locally but do NOT upload to HF yet
470
+ state["file_states"][wav_file] = "processed"
471
  uploaded_count += 1
472
  progress['uploaded_count'] = uploaded_count
473
  save_progress(progress)
474
  print(f"[{FLOW_ID}] ✅ {wav_filename} uploaded (#{uploaded_count})")
475
  else:
476
+ state["file_states"][wav_file] = "failed"
477
  print(f"[{FLOW_ID}] ❌ Failed to upload {wav_filename}")
478
  else:
479
+ state["file_states"][wav_file] = "failed"
480
  print(f"[{FLOW_ID}] ❌ Transcription failed for {wav_filename}")
481
 
482
  except Exception as e:
483
  print(f"[{FLOW_ID}] Error processing result for {wav_filename}: {e}")
484
+ state["file_states"][wav_file] = "failed"
485
  finally:
486
  # Release the server
487
  await release_server(server)