Spaces:
Paused
Paused
Commit ·
cd5aaf7
1
Parent(s): eb4ae44
Run Claude transcript-cleanup batches concurrently
Browse filesAn hour-long meeting is ~30 batches of 30 segments; sent one after another
they added several minutes to every long job. Batches are independent, so
they now go 6 at a time, with output order, hallucination stripping and
per-batch failure fallback unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -502,16 +502,15 @@ def _enhance_segments_with_claude(segments: list, language: str) -> list:
|
|
| 502 |
"Return ALL segment numbers, one per line, format: [N] corrected text"
|
| 503 |
)
|
| 504 |
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
batch = segments[batch_start: batch_start + _BATCH_SIZE]
|
| 508 |
numbered = "\n".join(
|
| 509 |
f"[{i}] {seg.get('text', '').strip()}"
|
| 510 |
for i, seg in enumerate(batch)
|
| 511 |
if seg.get("text", "").strip()
|
| 512 |
)
|
| 513 |
if not numbered:
|
| 514 |
-
|
| 515 |
|
| 516 |
try:
|
| 517 |
msg = client.messages.create(
|
|
@@ -543,17 +542,24 @@ def _enhance_segments_with_claude(segments: list, language: str) -> list:
|
|
| 543 |
for i, seg in enumerate(batch):
|
| 544 |
corrected = result_map.get(i)
|
| 545 |
if corrected is None:
|
| 546 |
-
|
| 547 |
elif corrected == "HALLUCINATED":
|
| 548 |
logger.info(f"Stripped hallucination (Claude): {seg.get('text', '')!r}")
|
| 549 |
else:
|
| 550 |
-
|
| 551 |
|
| 552 |
except Exception as e:
|
| 553 |
logger.warning(f"Claude batch enhancement failed: {e} — keeping originals")
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
|
| 559 |
def _add_diacritics_with_claude(text: str, language: str) -> str:
|
|
|
|
| 502 |
"Return ALL segment numbers, one per line, format: [N] corrected text"
|
| 503 |
)
|
| 504 |
|
| 505 |
+
def _process(batch: list) -> list:
|
| 506 |
+
out: list = []
|
|
|
|
| 507 |
numbered = "\n".join(
|
| 508 |
f"[{i}] {seg.get('text', '').strip()}"
|
| 509 |
for i, seg in enumerate(batch)
|
| 510 |
if seg.get("text", "").strip()
|
| 511 |
)
|
| 512 |
if not numbered:
|
| 513 |
+
return out
|
| 514 |
|
| 515 |
try:
|
| 516 |
msg = client.messages.create(
|
|
|
|
| 542 |
for i, seg in enumerate(batch):
|
| 543 |
corrected = result_map.get(i)
|
| 544 |
if corrected is None:
|
| 545 |
+
out.append(seg)
|
| 546 |
elif corrected == "HALLUCINATED":
|
| 547 |
logger.info(f"Stripped hallucination (Claude): {seg.get('text', '')!r}")
|
| 548 |
else:
|
| 549 |
+
out.append({**seg, "text": corrected})
|
| 550 |
|
| 551 |
except Exception as e:
|
| 552 |
logger.warning(f"Claude batch enhancement failed: {e} — keeping originals")
|
| 553 |
+
out.extend(batch)
|
| 554 |
+
return out
|
| 555 |
+
|
| 556 |
+
# Batches are independent, so send them concurrently: an hour-long
|
| 557 |
+
# meeting is ~30 batches, which took several minutes one after another.
|
| 558 |
+
from concurrent.futures import ThreadPoolExecutor as _Pool
|
| 559 |
+
batches = [segments[i:i + _BATCH_SIZE] for i in range(0, len(segments), _BATCH_SIZE)]
|
| 560 |
+
with _Pool(max_workers=min(6, max(1, len(batches)))) as pool:
|
| 561 |
+
results = list(pool.map(_process, batches))
|
| 562 |
+
return [seg for part in results for seg in part]
|
| 563 |
|
| 564 |
|
| 565 |
def _add_diacritics_with_claude(text: str, language: str) -> str:
|