Fix: run heavy pipeline in threads to unblock event loop, mount code volumes for live updates
This commit is contained in:
parent
2eee05a52f
commit
24154665b6
@ -75,13 +75,14 @@ async def process_file(file_path: Path, task_id: str):
|
|||||||
|
|
||||||
await _send_progress(task_id, 15, "Загрузка моделей ИИ...", "processing")
|
await _send_progress(task_id, 15, "Загрузка моделей ИИ...", "processing")
|
||||||
|
|
||||||
# Подготовка аудио
|
# Подготовка аудио (в отдельном потоке, чтобы не блокировать event loop)
|
||||||
audio_path = prepare_audio_input(str(file_path))
|
audio_path = await asyncio.to_thread(prepare_audio_input, str(file_path))
|
||||||
|
|
||||||
await _send_progress(task_id, 25, "Транскрибация (распознавание речи)...", "processing")
|
await _send_progress(task_id, 25, "Транскрибация (распознавание речи)...", "processing")
|
||||||
|
|
||||||
# Запуск пайплайна
|
# Запуск пайплайна (в отдельном потоке)
|
||||||
result = run_pipeline(
|
result = await asyncio.to_thread(
|
||||||
|
run_pipeline,
|
||||||
input_path=str(file_path),
|
input_path=str(file_path),
|
||||||
profile_name=None,
|
profile_name=None,
|
||||||
config_path=None,
|
config_path=None,
|
||||||
@ -94,18 +95,18 @@ async def process_file(file_path: Path, task_id: str):
|
|||||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
folder_name = f"{stem}_{timestamp}"
|
folder_name = f"{stem}_{timestamp}"
|
||||||
output_dir = PROCESSED_DIR / folder_name
|
output_dir = PROCESSED_DIR / folder_name
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
await asyncio.to_thread(output_dir.mkdir, parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Сохраняем docx и md
|
# Сохраняем docx и md (в отдельном потоке)
|
||||||
docx_path = str(output_dir / f"{stem}.docx")
|
docx_path = str(output_dir / f"{stem}.docx")
|
||||||
md_path = str(output_dir / f"{stem}.md")
|
md_path = str(output_dir / f"{stem}.md")
|
||||||
|
|
||||||
build_document(result["segments"], docx_path, config)
|
await asyncio.to_thread(build_document, result["segments"], docx_path, config)
|
||||||
build_document(result["segments"], md_path, config)
|
await asyncio.to_thread(build_document, result["segments"], md_path, config)
|
||||||
|
|
||||||
# Также сохраняем исходник (всегда копируем, так как папка уникальная)
|
# Также сохраняем исходник
|
||||||
src_copy = output_dir / file_path.name
|
src_copy = output_dir / file_path.name
|
||||||
shutil.copy2(str(file_path), str(src_copy))
|
await asyncio.to_thread(shutil.copy2, str(file_path), str(src_copy))
|
||||||
|
|
||||||
result_data = {
|
result_data = {
|
||||||
"docx": str(docx_path),
|
"docx": str(docx_path),
|
||||||
|
|||||||
@ -13,6 +13,9 @@ services:
|
|||||||
- uploads:/app/uploads
|
- uploads:/app/uploads
|
||||||
- processed:/app/processed
|
- processed:/app/processed
|
||||||
- tmp:/app/tmp
|
- tmp:/app/tmp
|
||||||
|
- ./backend:/app/backend:ro
|
||||||
|
- ./src:/app/src:ro
|
||||||
|
- ./scripts:/app/scripts:ro
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
entrypoint: ["uvicorn"]
|
entrypoint: ["uvicorn"]
|
||||||
command: ["backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
command: ["backend.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user