liuyang commited on
Commit
9e14752
·
1 Parent(s): 646c8e8

fix field key

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -262,7 +262,6 @@ def prepare_and_save_audio_for_model(task: dict, out_dir: str) -> dict:
262
  and a "chunks" array containing metadata dict(s) for each processed chunk.
263
  This structure is returned for both single and multiple chunk inputs.
264
  """
265
- chunks = task["chunk"]
266
  result = {
267
  "job_id": task.get("job_id", "job"),
268
  "channel": task["channel"],
@@ -272,8 +271,9 @@ def prepare_and_save_audio_for_model(task: dict, out_dir: str) -> dict:
272
  }
273
 
274
  # Handle both single chunk and multiple chunks
275
- if isinstance(chunks, list):
276
  # Process multiple chunks
 
277
  results = []
278
  for chunk in chunks:
279
  # Create a task for each chunk
@@ -1024,7 +1024,7 @@ class WhisperTranscriber:
1024
  """
1025
  try:
1026
  print("Transcribing segments...")
1027
-
1028
  # Step 1: Preprocess per chunk JSON
1029
  chunks = pre_meta["segments"]
1030
  for chunk in chunks:
@@ -1034,23 +1034,22 @@ class WhisperTranscriber:
1034
  base_offset_s = float(chunk.get("abs_start_ms", 0)) / 1000.0
1035
 
1036
  # Step 2: Transcribe full audio once
1037
- transcription_results, detected_language = self.transcribe_full_audio(
1038
  wav_path, language, translate, prompt, batch_size, base_offset_s=base_offset_s, clip_timestamps=None, model_name=model_name, transcribe_options=transcribe_options
1039
  )
1040
-
1041
  # Step 6: Return results
1042
- result = {
1043
- "chunk_idx": chunk["chunk_idx"],
1044
- "channel": chunk["channel"],
1045
- "job_id": pre_meta["job_id"],
1046
- "segments": transcription_results,
1047
- "language": detected_language,
1048
- "batch_size": batch_size,
1049
- }
1050
  # job_id = pre_meta["job_id"]
1051
  # task_id = pre_meta["chunk_idx"]
1052
  filekey = pre_meta["filekey"]#f"ai-transcribe/split/{job_id}-{task_id}.json"
1053
- ret = upload_data_to_r2(json.dumps(result), "intermediate", filekey)
1054
  if ret:
1055
  return {"filekey": filekey}
1056
  else:
 
262
  and a "chunks" array containing metadata dict(s) for each processed chunk.
263
  This structure is returned for both single and multiple chunk inputs.
264
  """
 
265
  result = {
266
  "job_id": task.get("job_id", "job"),
267
  "channel": task["channel"],
 
271
  }
272
 
273
  # Handle both single chunk and multiple chunks
274
+ if task.get("segments", None):
275
  # Process multiple chunks
276
+ chunks = task["segments"]
277
  results = []
278
  for chunk in chunks:
279
  # Create a task for each chunk
 
1024
  """
1025
  try:
1026
  print("Transcribing segments...")
1027
+ transcription_results = []
1028
  # Step 1: Preprocess per chunk JSON
1029
  chunks = pre_meta["segments"]
1030
  for chunk in chunks:
 
1034
  base_offset_s = float(chunk.get("abs_start_ms", 0)) / 1000.0
1035
 
1036
  # Step 2: Transcribe full audio once
1037
+ transcription_result, detected_language = self.transcribe_full_audio(
1038
  wav_path, language, translate, prompt, batch_size, base_offset_s=base_offset_s, clip_timestamps=None, model_name=model_name, transcribe_options=transcribe_options
1039
  )
1040
+
1041
  # Step 6: Return results
1042
+ result = {}
1043
+ result.update(chunk)
1044
+ result["segments"] = transcription_result
1045
+ result["language"] = detected_language
1046
+ result["batch_size"] = batch_size
1047
+
1048
+ transcription_results.append(result)
 
1049
  # job_id = pre_meta["job_id"]
1050
  # task_id = pre_meta["chunk_idx"]
1051
  filekey = pre_meta["filekey"]#f"ai-transcribe/split/{job_id}-{task_id}.json"
1052
+ ret = upload_data_to_r2(json.dumps(transcription_results), "intermediate", filekey)
1053
  if ret:
1054
  return {"filekey": filekey}
1055
  else: