fix(agent): proxy gradio config and reduce translate blocking
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# @RATIONALE Extracted from TranslationExecutor. Batch insert delegated to _batch_insert.py.
|
||||
# @REJECTED Keeping batch processing inside TranslationExecutor — caused class to exceed INV_7.
|
||||
|
||||
import asyncio
|
||||
from datetime import UTC, datetime
|
||||
import time
|
||||
from typing import Any
|
||||
@@ -66,7 +67,7 @@ class BatchProcessingService:
|
||||
tls = [str(tls)] if not isinstance(tls, list) else tls
|
||||
|
||||
# ★ Run local language detection on all rows (heuristic, no LLM)
|
||||
self._detect_languages(batch_rows, tls)
|
||||
await self._detect_languages(batch_rows, tls)
|
||||
|
||||
source_texts = [r.get("source_text", "") for r in batch_rows if r.get("source_text")]
|
||||
rc = batch_rows[0].get("source_data") if batch_rows else None
|
||||
@@ -135,14 +136,15 @@ class BatchProcessingService:
|
||||
# #region _detect_languages [C:2] [TYPE Function] [SEMANTICS translate,language,detect,lingua]
|
||||
# @ingroup Translate
|
||||
# @BRIEF Run local language detection on all batch rows (no LLM).
|
||||
def _detect_languages(self, batch_rows: list[dict], target_languages: list[str]) -> None:
|
||||
async def _detect_languages(self, batch_rows: list[dict], target_languages: list[str]) -> None:
|
||||
"""Run local language detection on all batch rows (no LLM).
|
||||
|
||||
Attaches '_detected_lang' (BCP-47 code or 'und') to each row dict.
|
||||
Uses batch_detect() for efficient multi-text processing.
|
||||
Uses batch_detect() for efficient multi-text processing, offloaded
|
||||
to a thread to avoid blocking the event loop.
|
||||
"""
|
||||
texts = [row.get("source_text", "") for row in batch_rows]
|
||||
results = batch_detect(texts, target_languages)
|
||||
results = await asyncio.to_thread(batch_detect, texts, target_languages)
|
||||
for row, lang in zip(batch_rows, results):
|
||||
row["_detected_lang"] = lang
|
||||
# #endregion _detect_languages
|
||||
|
||||
Reference in New Issue
Block a user